gpt4 book ai didi

ios - 按下主页按钮时启动主 ViewController

转载 作者:行者123 更新时间:2023-11-29 12:05:59 26 4
gpt4 key购买 nike

我正在做一个 Objective-C 应用程序,它有几个独立的 ViewControllers。当用户按下主页按钮并且应用程序进入后台模式时,我想显示我的主 ViewController。我找到的所有解决方案都是针对导航 Controller 的。在这种情况下,如何启动(以及在何处)ViewController?

谢谢

已解决:最后我通过添加 AppDelegate 解决了这个问题:

- (void)applicationWillEnterForeground:(UIApplication *)application
{
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.

ViewController *viewController=[[UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil] instantiateViewControllerWithIdentifier:@"ViewController"];
self.window.rootViewController = viewController;
}

最佳答案

您应该在主视图 Controller 中注册 UIApplicationDidEnterBackgroundNotification。发布通知后,您应该将导航堆栈弹出到主视图 Controller 。

[self.navigationController popToRootViewControllerAnimated:YES];

或者,如果这不是您应该使用的 Root View Controller :

[self.navigationController popToViewController:self animated:YES];

关于ios - 按下主页按钮时启动主 ViewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35015878/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com