0

ARC を使用し、iOS7 (iPhone 5S) でテストしています。

プッシュされた UIViewController (b) を持つナビゲーション コントローラー (a) があります。b は、手動セグエを介してモーダル NavigationViewController (c) を提示します。c は次に UIViewController (d) をプッシュします。

これで、1 つのルートと 1 つのモーダルの 2 つのナビゲーション スタックができました。

バックグラウンドに移動するたびに、モーダル NavigationViewController (c) とそのすべての子を閉じたいと思います。

UIViewController (b) には、次のコードがあります。

- (void)viewDidLoad
{
    [super viewDidLoad];
    [[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(enteredBackground:)
                                             name:UIApplicationDidEnterBackgroundNotification object:nil];

}
-(void)enteredBackground:(NSNotification *)notification{
    if (self.presentedViewController) {
        [self dismissViewControllerAnimated:NO completion:nil];
    }
}
- (void)dealloc {
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}

これは、バックグラウンドに移動するときに C の rootViewController を使用している場合は正常に機能しますが、D を使用している場合はクラッシュします。

2013-10-20 22:49:49.008 MyApp[2596:60b] *** -[UIView release]: message sent to deallocated instance 0x17036aa40

これを修正するにはどうすればよいですか? モーダル ナビゲーション スタックのビューが送信されdealloc、既に解放されているようです。デバッガーを調べたところ、モーダル nvaigationcontroller (c) 自体はまだ存在しているようです。

4

1 に答える 1