我有三個viewControllers
,我試圖發送一個通知從viewController
3到viewController
1和2.我認爲最好的方法是使用NSNotification
。這是我到目前爲止有:我應該從哪裏把removeObserver從NSNotification
在C類 - 發佈通知
[[NSNotificationCenter defaultCenter] postNotficationName:@"Updated "object:self];
在B類
在類和B類 - 先註冊爲通知
// viewDidLoad
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleUpdate:) name:@"Updated" object:nil];
-(void)handleUpdate:(NSNotification *)notification {
NSLog(@"recieved");
}
此功能到目前爲止。但在類A和B,當我去註冊吧:
- (void)viewWillDisappear:(BOOL)animated {
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
的handleUpdate
方法不會被調用。所以明顯的問題是當我012bd爲notification
。
我的問題是,如果我迄今所做的一切都是正確的,那麼爲什麼當我刪除removeObserver
時它不工作?如果不正確,我可以在哪裏removeObserver's
?
in方法dealloc –
謝謝!簡直不敢相信! – Jessica