当应用程序进入后台时,关闭popover

Ash*_*ani 1 iphone uipopovercontroller ios

当应用程序进入后台时如何解除popover?

Dil*_*lip 5

您可以使用appdelegate.m文件中的委托方法执行此操作

- (void)applicationDidEnterBackground:(UIApplication *)application
{
    //put your dissmiss popover code here
}
Run Code Online (Sandbox Code Playgroud)

  • 要使这个方法起作用,你需要在appDelegate中保留popoverController的引用,这可能不是一个好的选择.@David Haynes和nsgulliver的答案会更好. (2认同)

nsg*_*ver 5

最好是在你的应用程序进入后台时注册你的控制器UIApplicationDidEnterBackgroundNotification或者UIApplicationWillResignActiveNotification解雇它,这会让你的生活变得更加轻松.

在您的注册中注册通知 viewDidLoad

[[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(myMethod)
                                                 name:UIApplicationDidEnterBackgroundNotification object:nil];
Run Code Online (Sandbox Code Playgroud)

实现方法和

  -(void)myMethod{
    // dismiss popview here
    }
Run Code Online (Sandbox Code Playgroud)

最后从视图控制器中的通知中取消注册

-(void)dealloc{
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
Run Code Online (Sandbox Code Playgroud)