我有一個UITabBarController
兩個選項卡,我註冊了兩個NSNotificationCenter
,我的問題是我沒有收到隱藏選項卡上的通知(即其尚未被稱爲viewDidAppear:
)。我的想法是控制器不在屏幕上(即隱藏)不響應NSNotifications
。我可以做一些不同的方式,這不是一個問題,但我只是想驗證爲什麼隱藏的標籤沒有得到通知,以防我失去了其他東西,它應該實際上正在工作...隱藏的視圖是否對NSNotifications有反應?
編輯:
@Fab1n指出我在正確的方向,我錯誤地使用viewWillDisappear:
刪除觀察員,所以當視圖消失是不再收聽通知。我會把它移動到dealloc
。
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
NSNotificationCenter *notificationCenter = [NSNotificationCenter defaultCenter];
[notificationCenter removeObserver:self];
}
更改爲:
- (void)dealloc {
NSNotificationCenter *notificationCenter = [NSNotificationCenter defaultCenter];
[notificationCenter removeObserver:self];
}
十分讚賞。
您何時註冊並取消註冊通知?你可以顯示該代碼嗎? – jrturton 2013-04-09 08:07:06
我想換個問題「消失的視圖控制器是否響應NSNotifications」? – voromax 2013-04-09 08:18:27
使用viewWillAppear – Rajneesh071 2013-04-09 09:38:12