Ios:当应用程序进入非事件状态时,如何让我的应用程序返回 Root View

标签 ios view uinavigationcontroller switching appdelegate

我希望我的应用程序在不活动时返回登录屏幕(这是导航 Controller 中的 Root View )。

我在 applicationWillResignActive 中,appdelegate.m 无法识别 self.navigationController

我试图在 Storyboard中使用 ctrl 拖动在 appdelegate.h 中创建一个 socket 或导航 Controller ,但它不允许我这样做。

那么有人知道如何让它在不活动时切换到特定 View 吗?

最佳答案

您可以在应用程序返回时通过在方法 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];
}

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

关于Ios:当应用程序进入非事件状态时,如何让我的应用程序返回 Root View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12064667/

相关文章:

ios - Xcode 不部署或启动 Apple Watch 模拟器

ios - Swift 中的 colorWithAlphaComponent 示例

iOS - 导航 Controller 和自定义 View

ios - 设置自定义导航栏后 Segue 无法正常工作

ios - 如何修复 GADDelegateManager didYouNilOutYourDelegate :selector: error

ios - 如何使用 blender 和 PowerVR SDK 为 cocos3d 创建一个简单的 3d 球体

android - 如何将 "complex"阴影添加到 android 中的 View ?

sql - Oracle 可以使用 PARTITION BY 分析函数对查询使用谓词推送吗?

android - OnTouchListener - ActionMove (android) 在一个触摸点给出不同的位置

iphone - 如何在代码中将 UINavigationController 添加到 View ?