我在AppDelegate.h文件添加以下代碼:我應該在applicationWillTerminate中刪除觀察者嗎?
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(saveDataAndSettings)
name:UIApplicationDidEnterBackgroundNotification
object:nil];
}
我通常這樣寫:
- (void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
如果我設置的UIViewController類是觀察者(非ARC)。
我想知道,不過,如果我在AppDelegate中做到這一點,我應該還是插入此行:
[[NSNotificationCenter defaultCenter] removeObserver:self];
在applicationWillTerminate:方法。
因爲應用程序將被終止,這樣做是否有意義?
在此先感謝
謝謝你的答案 – ppalancica 2014-10-17 22:56:21
不用擔心,我通常不張貼了很多問題,但是當我這樣做時,我接受很好的答案,而你的確很棒! – ppalancica 2014-10-18 00:18:24