[英]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 . 本地通知文本来自MainViewController中的数组。 Yet i have to set it's title in the AppDelegate ... 但是我必须在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 . 问题是-按钮的文本放置在MainViewController的second array
中。 How would you guys handle such a thing? 你们将如何处理这样的事情?
Thank you! 谢谢!
If I were you, I would make this array a public variable in MainViewController
. 如果我是你,我将在MainViewController
将此数组MainViewController
一个公共变量。 Also, I would have a reference to MainViewController
in AppDelegate
. 另外,我将在AppDelegate
引用MainViewController
。 Then simply refer to MainViewController
instance in AppDelegate
and get that array. 然后只需引用AppDelegate
MainViewController
实例并获取该数组。
Alternatively, you can create a similar array variable in AppDelegate
. 或者,您可以在AppDelegate
创建类似的数组变量。 When MainViewController
is loaded and the title array is computed, access AppDelegate
and the title array on AppDelegate
. 当MainViewController
被加载和标题阵列计算,访问AppDelegate
和在标题阵列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
? 附带说明一下,如果这是一个静态数组,为什么不简单地在AppDelegate
设置它呢?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.