xcode 在应用程序委托中弹出到根视图控制器
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12625249/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Pop to root view controller in app delegate
提问by Travis M.
I have an app that someone logs into and if they launch it after sending it to the background for more than 10 minutes I pop up a nice little "session expired" alert and send them to the root view controller (login page).
我有一个应用程序,有人登录,如果他们在将它发送到后台超过 10 分钟后启动它,我会弹出一个漂亮的小“会话已过期”警报并将它们发送到根视图控制器(登录页面)。
Everything works great but I don't know how to pop to the root view controller in my navigation controller stack from the app delegate's applicationWillEnterForeground: method.
一切正常,但我不知道如何从应用程序委托的 applicationWillEnterForeground: 方法弹出到导航控制器堆栈中的根视图控制器。
I tried saving off the navigationController onto an appDelegate variable but I wonder if the app is in the background for several days, if iOS starts freeing some variables, as I get an error in this method at that time.
我尝试将 navigationController 保存到 appDelegate 变量上,但我想知道该应用程序是否在后台运行了几天,iOS 是否开始释放一些变量,因为当时我在此方法中遇到错误。
Any ideas?
有任何想法吗?
回答by Dan F
If the navigation controller is your application's root view controller, then you can get it like:
如果导航控制器是您应用程序的根视图控制器,那么您可以像这样获得它:
UINavigationController *myNavCon = (UINavigationController*)self.window.rootViewController;
where self
is in the app delegate
在self
应用程序委托中的位置
回答by mhrrt
Just to make things more clear one can use following to pop to rootviewcontroller from AppDelegate
只是为了让事情更清楚,可以使用以下内容从 AppDelegate 弹出到 rootviewcontroller
UINavigationController *navigationController = (UINavigationController *)self.window.rootViewController;
[navigationController popToRootViewControllerAnimated:YES];
Here self is app delegate.
这里 self 是应用程序委托。