ios - 如何删除 UIViewController?

标签 ios uiviewcontroller ios6

在我的应用程序工作流程中的某个时刻,我有一个显示 UIViewController。当我按下“主页”按钮时,我会离开该应用程序,使其在后台运行。

但是,当我返回应用程序时,我希望显示的 UIViewController 不再出现。我希望它被删除或销毁或类似的事情。

我怎样才能做到这一点?

最佳答案

您可以在 viewcontroller 类中向 UIApplicationDidEnterBackgroundNotification 添加观察者。在 init 方法中尝试一下:

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

然后在 EnterBackground 方法中,您可以弹出或关闭您的 viewcontroller

记住调用这个

[[NSNotificationCenter defaultCenter] removeObserver:self name:UIApplicationDidEnterBackgroundNotification object:nil];

dealloc

关于ios - 如何删除 UIViewController?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13495326/

相关文章:

ios - wireguard ios,路由 ip+net : sysctl: operation not supported

ios - 获取分页UIScrollView中可见 View Controller

ios - 目标 View Controller 何时在 segue 期间初始化?

objective-c - iOS 6 : CoreAnimation: warning, 删除了未提交 CATransaction 的线程

ios - 如何根据 iOS 版本加载多个 Storyboard文件? (5 和 6)

ios - 如何将子图层居中放置在另一图层上?

iphone - 使文本输入在文本字段中的某个空格后开始

ios - 在 Swift 中将 managedObjectContext 从一个 ViewController 传递到另一个 ViewController?

javascript - 在 ios 6 上隐藏 safari 的地址栏

ios - 核心数据并发调试: False Positive