当应用程序进入后台时关闭modalviewcontroller [英] dismiss a modalviewcontroller when the application enters background

查看:120
本文介绍了当应用程序进入后台时关闭modalviewcontroller的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在应用程序进入后台时自动关闭uiimagepicker模态viewcontroller.我试图将代码放入viewdiddissappear方法中的dismissmodalviewcontroller代码中,但没有被调用.所以我在appdelegate中引用了viewcontroller并尝试了将其放在applicationdidenterbackground方法中,但仍无法正常工作.有人可以指出正确的方法

i need to dismiss my uiimagepicker modal viewcontroller automatically when the application enters the background.i tried to put the code to dismissmodalviewcontroller code in viewdiddissappear method,but its not being called.so i made a reference to the viewcontroller in appdelegate and tried to put it in the applicationdidenterbackgroundmethod but still it is not working.can someone point out the right way to do this

推荐答案

尝试在要关闭的UIViewController中为UIApplicationDidEnterBackgroundNotification添加NSNotificationCenter观察器.使用选择器关闭模态视图

Try to add an NSNotificationCenter observer for UIApplicationDidEnterBackgroundNotification in the UIViewController that you want to dismiss. Use the selector to dismiss the modalview

- (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];
}

这篇关于当应用程序进入后台时关闭modalviewcontroller的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆