4
什麼時候應該添加和刪除UIApplication通知的觀察者?我應該何時添加/刪除UIApplication Notifications的觀察者?
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
[nc addObserver:self selector:@selector(saveState) name:UIApplicationWillResignActiveNotification object:nil];
[nc addObserver:self selector:@selector(loadState) name:UIApplicationWillEnterForegroundNotification object:nil];
}
和
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
[self.navigationController setNavigationBarHidden:YES animated:animated];
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
[nc removeObserver:self name:UIApplicationWillResignActiveNotification object:nil];
[nc removeObserver:self name:UIApplicationWillEnterForegroundNotification object:nil];
}
這是壞?當視圖在屏幕上時,我只對通知感興趣。如果在viewWillDisappear:
方法中刪除UIApplicationWillEnterForegroundNotification
會有什麼問題嗎?我在想事情發生的順序......?