[英]NSNotificationCenter crash after changing UIViewController
我現在正在實現一個帶有iOS SDK 6.0的應用程序,但遇到了問題。
當我第一次打開我的UIViewcontroller時,我在其中實現了一些NSNotificationCenter來檢測用戶何時單擊主頁按鈕,當我嘗試單擊主頁按鈕並返回到我的應用時,它看起來像在工作。 但是問題是,當我使用UIViewcontroller並轉到另一個UIViewcontroller並嘗試單擊“主頁”按鈕時,應用程序看起來像崩潰了。
這是我的代碼:
In the viewDidLoad function :
[[NSNotificationCenter defaultCenter] addObserver: self
selector: @selector(ApplicationEnteringBackground)
name: UIApplicationDidEnterBackgroundNotification
object: nil];
[[NSNotificationCenter defaultCenter] addObserver: self
selector: @selector(ApplicationEnteringForeground)
name: UIApplicationWillEnterForegroundNotification
object: nil];
我只是實現了方法:
-(void)ApplicationEnteringBackground
{
...
}
-(void)ApplicationEnteringForeground
{
...
}
問題看起來像這樣:
感謝您的幫助=)
確保在第一個視圖控制器銷毀時正在移除觀察者[[NSNotificationCenter defaultCenter] removeObserver:self];
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.