Reputation: 4190
Is there a way to test in viewWillDisappear if it's being called because the application is exiting, versus normal ways of it being dismissed? The method applicationWillTerminate in the App Delegate is called after the current view is closed. I want to do different things depending on whether it's being dismissed due to a IBAction or the user clicking the menu button.
Thanks!
Upvotes: 3
Views: 2637
Reputation: 15511
You should use observe the UIApplicationWillTerminateNotification
in your controller, set a flag, and then check for the flag in your viewWillDisappear
implementation.
NSNotificationCenter* defaultCenter = [NSNotificationCenter defaultCenter];
[defaultCenter addObserver:self
selector:@selector(applicationWillTerminate:)
name:UIApplicationWillTerminateNotification
object:nil];
Upvotes: 3
Reputation: 2498
I haven't used it for your purposes yet, but the UIApplicationWillResignActiveNotification notification might occur before applicationWillTerminate is called.
Just throw...
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationWillResign:) name:UIApplicationWillResignActiveNotification object:NULL];
... into your UIViewController to test it out.
Upvotes: 1