【问题标题】:Ios: How can I make my app go back to root view when App goes InactiveIos:当应用程序处于非活动状态时,如何让我的应用程序返回根视图
【发布时间】:2012-08-21 23:55:18
【问题描述】:

我希望我的应用在处于非活动状态时返回登录屏幕(导航控制器中的根视图)。

我在 applicationWillResignActive 并且 appdelegate.m 无法识别 self.navigationController

我尝试在故事板中使用 ctrl 拖动在 appdelegate.h 中创建一个插座或导航控制器,但它不会让我这样做。

那么有谁知道如何让它在不活动时切换到特定视图?

【问题讨论】:

标签: ios view uinavigationcontroller switching appdelegate


【解决方案1】:

当您的应用返回时,您可以通过在 applicationWillEnterForeground 或 applicationDidBecomeActive 方法中执行该代码来显示原始 uiviewcontroller

快速代码

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

我确信这不是唯一或最好的方法,但它在技术上有效

【讨论】:

  • 感谢您的编辑。那行得通,不过我把它放在 willResignActive 中。
猜你喜欢
  • 2015-03-20
  • 1970-01-01
  • 1970-01-01
  • 2020-01-26
  • 1970-01-01
  • 1970-01-01
  • 2013-05-08
  • 2013-03-09
  • 2011-09-19
相关资源
最近更新 更多