如果我使用 NSNotifications
告诉我UITableViews
(在不同的Controllers)添加一个新的Cell,但是那个Controller在哪个UITableView
谎言尚未被“访问”或加载/初始化, Controller 将不会收到消息(因为我的 NSNotificationCenter
在我的每个 viewDidLoad
中设置)。据我了解,这是预期的行为。
现在我的问题是:有没有办法让尚未访问的 Controller 在应用程序启动后收到通知?或者有没有更好的方法发布到另一个UIViewController
的 UITableView
来自不同的 UIView
而不是使用 NSNotifications
?
我看到了一个类似的 question几年前问过,所以如果有人能插话,将不胜感激!
最佳答案
如果你想让你的 Controller 在它被访问之前收到一个通知(即它的 View 被加载并且 viewDidLoad
被调用)那么你需要在 init
方法:
如果您想以编程方式创建 Controller ,则需要在
init
或initWithStyle:
方法中进行。如果您想从
.xib
文件以编程方式创建您的 Controller ,那么您需要在initWithNibName:bundle:
方法中进行。如果您想从
.storyboard
文件创建您的 Controller ,那么您需要在initWithCoder:
方法中进行。
关于ios - NSNotification : possible to receive when Controller doesn't exist yet?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23132011/