UIApplication 通知のオブザーバーをいつ追加および削除する必要がありますか?
- (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];
}
これは悪いですか?ビューが画面に表示されているときの通知にのみ関心があります。UIApplicationWillEnterForegroundNotification
また、viewWillDisappear:
メソッド内のを削除しても問題はありませんか? 順番とか考えてる…?