我应该在哪里删除通知观察员?

nev*_*ing 5 iphone notifications cocoa-touch objective-c nsnotifications

我在视图控制器的init方法中设置了一个通知观察器,如下所示:

[[NSNotificationCenter defaultCenter] 
                    addObserver:self
                    selector:@selector(saveState)
                    name:UIApplicationWillResignActiveNotification
                    object:nil];
Run Code Online (Sandbox Code Playgroud)

removeObserver:name:object:这个通知的最佳地点在哪里?我现在用我的dealloc方法调用它,但想知道这是否会导致问题.

Lil*_*ard 8

不,你做对了.dealloc是删除通知观察者的正确位置(除非您有一些特定的理由需要先删除观察者).