Reputation: 7095
At some point in my application workflow, I have one showing UIViewController
. And as I press the Home button, I leave the application, leaving it running in the background.
However, when I return to the app, I would like the showing UIViewController
not to appear again. I would like it to be removed or destroyed or anything like that.
How can I accomplish that?
Upvotes: 2
Views: 214
Reputation: 293
You may add observer to UIApplicationDidEnterBackgroundNotification in your viewcontroller
class. Try this in the init
method:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(enterBackground) name:UIApplicationDidEnterBackgroundNotification object:nil];
then in the enterBackground method, you can pop or dismiss your viewcontroller
.
remember call this
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIApplicationDidEnterBackgroundNotification object:nil];
in the dealloc
Upvotes: 1
Reputation: 31026
There is a notification you can register to receive that's called UIApplicationDidEnterBackgroundNotification
(also UIApplicationWillResignActiveNotification
). If you listen for that in your view controller, you can arrange for it to be popped or dismissed depending on how it came to be displayed in the first place.
Upvotes: 1