简体   繁体   中英

Sending a message from MainController to Delegate - Swift

I'm sending an interactive local notification with one button.
The local notification text is taken from an array in MainViewController . Yet i have to set it's title in the AppDelegate ...
Once this button is pressed - the app responds and sends me another local notification with different text and a different button title.

The issue is - the text for the button is placed in a second array in the MainViewController . How would you guys handle such a thing?

Thank you!

If I were you, I would make this array a public variable in MainViewController . Also, I would have a reference to MainViewController in AppDelegate . Then simply refer to MainViewController instance in AppDelegate and get that array.

Alternatively, you can create a similar array variable in AppDelegate . When MainViewController is loaded and the title array is computed, access AppDelegate and the title array on AppDelegate . Now, directly access this title array like a local variable.

As a side note, if this is a static array, why don't you simply set it in AppDelegate ?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM