Why viewWillDisappear or viewDidDisappear not called when app quit in iOS simulator?

Total Post:45

Points:323
iPhone  Ios 
 1599  View(s)
Ratings:
Rate this:

I'm trying to call removeObserver() when the app quits. But when I used NSLog() to check, I found neither viewWillDisappear() nor viewDidDisappear() was called after the app quit in iOS simulator. I'm using a single view template, not navigation controller in similar questions.

  1. Post:110

    Points:774
    Re: Why viewWillDisappear or viewDidDisappear not called when app quit in iOS simulator?

    These two methods will not be called when you quit the app. Instead, the method you can use observer


     [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(applicationDidEnterBackground:)name:UIApplicationDidEnterBackgroundNotification object:nil];

    (void)applicationDidEnterBackground:(NSNotification *)aNotification {
     // your  removeObserver code goes here.
        NSLog(@"applicationDidEnterBackground");

    }

Answer