在我的应用程序工作流程中的某个时刻,我有一个显示 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/