[英]How do I make a viewController appear when app loads?
I've got a working app that doesn't crash and I've set my initial VC to be the one I want. 我有一个不会崩溃的可正常运行的应用程序,并且已将我的初始VC设置为我想要的。 When running on the simulator, my app opens for the first time on the VC I want, but if I go to;
在模拟器上运行时,我的应用程序将在我想要的VC上第一次打开,但是如果我要打开的话; Hardware -> Home and click on the app again on the main iPhone menu, the app loads the VC I left with and not the VC I set an my main.
硬件->主页,然后再次在iPhone主菜单上单击该应用程序,该应用程序将加载我剩下的VC,而不是我设置主菜单的VC。 I'm new to iOS development so I don't understand what's not working.
我是iOS开发的新手,所以我不明白什么是行不通的。 Other questions's answers don't help me a bit since my main VC is set on my storyboard.
其他问题的答案对我的主VC设置在情节提要上没有任何帮助。 Thanks for the help guys!
感谢您的帮助! This is in my appDelegate file:
这是在我的appDelegate文件中:
func applicationWillResignActive(application: UIApplication) {
NSNotificationCenter.defaultCenter().addObserver(self, selector:"appWillResignActive", name:UIApplicationWillResignActiveNotification, object: nil)
func appWillResignActive() -> () {
self.navigationController?.popToViewController(ViewController, animated: false)
}
}
You can subscribe to the UIApplicationWillResignActiveNotification
and call a method right before the app goes to the background, to set the VC to the one you want. 您可以订阅
UIApplicationWillResignActiveNotification
并在应用程序进入后台之前调用方法,以将VC设置为所需的VC。 This way, once they re-open the app, it should be where you want it to be. 这样,一旦他们重新打开应用程序,它就应该在您想要的位置。
Obj-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)
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.