0

現在、iOS SDK 6.0 を使用してアプリケーションを実装していますが、問題があります。

ユーザーがホームボタンをクリックしたことを検出するためにいくつかの NSNotificationCenter を実装した UIViewcontroller を初めて開いたとき、ホームボタンをクリックしてアプリに戻ろうとすると動作しているように見えます。しかし、問題は、私が UIViewcontroller を使用しているときに別の 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
{
   ...
}

問題は次のようになります。

問題

助けてくれてありがとう =)

4

1 に答える 1

4

最初のView Controllerが破棄されたときにオブザーバーを削除していることを確認してください [[NSNotificationCenter defaultCenter] removeObserver:self];

于 2013-04-19T22:10:20.857 に答える