简体   繁体   English

Ios:当应用程序处于非活动状态时,如何让我的应用程序返回到根视图

[英]Ios: How can I make my app go back to root view when App goes Inactive

I want my app to go back to the login screen (Which is the root view in the navigation Controller) when it goes inactive. 我希望我的应用程序在处于非活动状态时返回登录屏幕(导航控制器中的根视图)。

I'm in applicationWillResignActive and appdelegate.m does not recognize self.navigationController 我在applicationWillResignActive和appdelegate.m无法识别self.navigationController

I tried to make an outlet or the navigation contller in appdelegate.h using ctrl drag in storyboard but it wouldn't let me. 我试图在appdelegate.h中使用ctrl拖动在故事板中制作出口或导航控制器,但它不会让我。

So does anyone know how to get it to switch to a specific view when it goes inactive? 那么有人知道如何在它变为非活动状态时切换到特定视图吗?

You could just display the original uiviewcontroller when your app comes back by doing that code in the method applicationWillEnterForeground or applicationDidBecomeActive 您可以在应用程序返回时通过在方法applicationWillEnterForeground或applicationDidBecomeActive中执行该代码来显示原始uiviewcontroller

quick code 快速代码

- (void)applicationWillEnterForeground:(UIApplication *)application
{
    // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
    UINavigationController *navigationController = (UINavigationController *)self.window.rootViewController;
    [navigationController popToRootViewControllerAnimated:YES];
}

I am sure not the only or best way to do it but it technically works 我肯定不是唯一或最好的方法,但它在技术上有效

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM