当应用程序进入后台时,我需要自动关闭我的uiimagepicker模态视图 Controller 。我尝试将代码放在viewdiddissappear方法中的dismissmodalviewcontroller代码中,但它没有被调用。所以我在appdelegate中引用了 View Controller 并尝试将其放入 applicationdidenterbackground 方法中,但它仍然不起作用。有人可以指出执行此操作的正确方法
最佳答案
尝试在要关闭的 UIViewController 中为 UIApplicationDidEnterBackgroundNotification 添加 NSNotificationCenter 观察者。使用选择器关闭模态视图
- (void)viewWillAppear:(BOOL)animated
{
[[NSNotificationCenter defaultCenter] addObserver: self
selector: @selector(didEnterBackground:)
name:UIApplicationDidEnterBackgroundNotification
object:nil];
}
- (void)viewWillDisappear:(BOOL)animated
{
[[NSNotificationCenter defaultCenter] removeObserver: self
name:UIApplicationDidEnterBackgroundNotification
object:nil];
}
- (void)didEnterBackground:(NSNotification*)note
{
[self.navigationController dismissModalViewAnimated:NO];
}
关于iphone - 当应用程序进入后台时关闭 modalviewcontroller,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5685419/