そのため、さまざまなケースで NSNotifications をテストしているだけですが、これは混乱を招きます。NSNotifications を理解するのを手伝っていただければ幸いです。
ナビゲーションコントローラーがあります。
「追加」という UIBarButtonItem があり、通知を投稿します DidAddNotification
[追加] をクリックすると、view2 にプッシュされます。
// I add view2 as observer and write method for this and NSlog if it gets implemented //
私は再び 3 を表示するように自分をプッシュします。
// I add view3 as another observer and use the same method as the previous view and I NSlog if it gets implemented//
ビュー 3 から popToRootViewControllerAnimated:YES を実行すると、1 に戻り、同じ手順を繰り返します。
コントロールはこんな感じで・・・
1 -> 2 -> 3 -> 1
if I press add again,
the control is again the same 1 -> 2-> 3-> 1
出力 (NSLogs) は次のとおりです。
初めて [追加] を押します。
2011-06-09 14:47:41.912 Tab[5124:207] I am the notification in view2
2011-06-09 14:47:41.912 Tab[5124:207] I pressed Add Button and I just sent a notification from view 1
// No notification in view 3 ?? // I am now back to view 1.
もう一度 [追加] を押します。
2011-06-09 14:47:51.950 Tab[5124:207] I am the notification in view3
2011-06-09 14:47:51.951 Tab[5124:207] I pressed Add Button and I just sent a notification from view 1
// No Notification in view 2 ??? // ... I am now back to view 1.
[追加] をもう一度押します。
2011-06-09 14:47:59.160 Tab[5124:207] I am the notification in view 3
2011-06-09 14:47:59.161 Tab[5124:207] I pressed Add Button and I just sent a notification from view 1
// No Notification in view 2 ??? // ... I am now back to view 1.
And this goes on..
誰か教えてくれませんか
- NSLog は最初はビュー 3 で印刷されませんでしたが、それ以外は常に印刷されますか?
- NSLog がビュー 2 で初めて印刷し、二度と印刷しないのはなぜですか?
コード:
[[NSNotificationCenter defaultCenter] postNotificationName:@"DidAddNotification" object:self]; // I put this in the - (IBAction) for addData
- (void)didPressAdd:(NSNotification *)notification { //NSLogs// }
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didPressAdd:) name:@"DidAddNotification" object:nil]; // I put this in the viewDidLoad of view 1 and view 2