Итак, я просто тестирую 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