So, I'm just testing NSNotifications on a variety of occasions, and this is confusing. I would appreciate it if you could help me understand NSNotifications!
I have a navigation controller.
I have a UIBarButtonItem called "Add" that sends a DidAddNotification notification
If I click Add, this will push me to view2.
// I add view2 as observer and write method for this and NSlog if it gets implemented //
I push myself again to view 3.
// I add view3 as another observer and use the same method as the previous view and I NSlog if it gets implemented//
From view 3, I popToRootViewControllerAnimated: YES, and I will return to 1. and perform the same procedure again.
So this is management ...
1 -> 2 -> 3 -> 1
if I press add again,
the control is again the same 1 -> 2-> 3-> 1
Here's the output (NSLogs) :
I click "Add" for the first time:
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.
I click the Add button again:
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.
I click "Add" again:
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..
Can anyone tell me why
:
[[NSNotificationCenter defaultCenter] postNotificationName:@"DidAddNotification" object:self];
- (void)didPressAdd:(NSNotification *)notification {
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didPressAdd:) name:@"DidAddNotification" object:nil];