0

I am making an app with different nav controllers. All of them are initially initialized.

Say, I have 3 nav controllers A, B and C.

A View controller from B (say B1) sends a notification that is supposed to be heard from view controller in A (say A1). After that, we go to view controller A1.

However, if we are in the view controller B1 from the beginning (and never went to View controller A1), then A1 doesnt get the notification. However, it gets it the second time.

OR, if I go inside A1 once, then the notifications are properly received.

Can anyone kindly help me out ? Thanks.

NB: the listeners code is in the init of A1. It gets hit (i checked by using breakpoints).

4

2 回答 2

0

由于您说在视图显示一次后收到通知,因此我怀疑您正在以一种在显示视图之前不会运行的方法注册通知(viewDidLoad,viewDidAppear:等)。

如果是这种情况,请尝试将通知注册移动到init您在 ViewControllers 中使用的任何方法。

于 2012-05-26T23:15:31.333 回答
0

NSNotification 可以通过所有应用程序观察到。因此,要执行您计划执行的操作,我会使用布尔标志或计数器。您可以将这些指标放在 appDelegate 类中或使用全局变量。

于 2012-05-27T16:57:08.750 回答