gpt4 book ai didi

ios - 如何在应用程序加载时显示 viewController?

转载 作者:行者123 更新时间:2023-11-28 11:21:00 27 4
gpt4 key购买 nike

我有一个不会崩溃的工作应用程序,我已将我的初始 VC 设置为我想要的那个。在模拟器上运行时,我的应用程序第一次在我想要的 VC 上打开,但如果我去;硬件 -> 主页并在 iPhone 主菜单上再次单击该应用程序,该应用程序加载我留下的 VC,而不是我设置的 VC。我是 iOS 开发的新手,所以我不明白什么不起作用。其他问题的答案对我没有一点帮助,因为我的主要 VC 设置在我的 Storyboard上。感谢您的帮助!这是在我的 appDelegate 文件中:

func applicationWillResignActive(application: UIApplication) {

NSNotificationCenter.defaultCenter().addObserver(self, selector:"appWillResignActive", name:UIApplicationWillResignActiveNotification, object: nil)

func appWillResignActive() -> () {
self.navigationController?.popToViewController(ViewController, animated: false)
}
}

最佳答案

您可以订阅 UIApplicationWillResignActiveNotification 并在应用进入后台之前调用一个方法,将 VC 设置为您想要的。这样,一旦他们重新打开应用程序,它就会出现在您想要的位置。

objective-C :

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(appWillResignActive) name:UIApplicationWillResignActiveNotification object:nil];

-(void) appWillResignActive {
[self.navigationController popToViewController:<UIViewController you want> animated:NO];
}

SWIFT:

NSNotificationCenter.defaultCenter().addObserver(self, selector:"appWillResignActive", name:UIApplicationWillResignActiveNotification, object: nil)

func appWillResignActive() -> () {
self.navigationController.popToViewController(<UIViewController you want>, animated: false)
}

关于ios - 如何在应用程序加载时显示 viewController?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28157753/

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