Ashwani
Ashwani

Reputation: 388

Dismiss popover when app goes in background

How to dismiss popover when application enters in background?

Upvotes: 1

Views: 1039

Answers (4)

nsgulliver
nsgulliver

Reputation: 12671

it is better to register your controller for UIApplicationDidEnterBackgroundNotification or UIApplicationWillResignActiveNotification and dismiss it whenever your app goes to background, this will make your life quite easier i feel.

registering for notification in your viewDidLoad

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

implement the method and

  -(void)myMethod{
    // dismiss popview here
    }

finally un-register from the notification in your view controller

-(void)dealloc{
[[NSNotificationCenter defaultCenter] removeObserver:self];
}

Upvotes: 5

Ravindhiran
Ravindhiran

Reputation: 5384

try this

- (void)applicationDidEnterBackground:(UIApplication *)application
{
   //[popover dissmissPopoverAnimated:YES];
}

Upvotes: 0

David Haynes
David Haynes

Reputation: 933

Send an NSNotification in your app delegate's willResignActive method, and listen for it in your view controller that contains the popup, and have it dismiss said popover when the notification is received.

Upvotes: 4

Dilip Manek
Dilip Manek

Reputation: 9143

You can do this using the delegate method in appdelegate.m file

- (void)applicationDidEnterBackground:(UIApplication *)application
{
    //put your dissmiss popover code here
}

Upvotes: 5

Related Questions