2015-01-26 71 views
0

我有一个工作的应用程序不会崩溃,我已经将我的初始VC设置为我想要的。在模拟器上运行时,我的应用第一次在我想要的VC上打开,但是如果我去了;硬件 - >首页,然后在主iPhone菜单上再次点击该应用程序,该应用程序加载我离开的VC,而不是VC,我设置了我的主。我是iOS开发新手,所以我不明白什么是不工作的。其他问题的答案对我来说并没有什么帮助,因为我的主要风险投资被设置在我的故事板上。谢谢你们的帮助!这是我的appDelegate文件:如何在应用程序加载时显示viewController?

func applicationWillResignActive(application: UIApplication) { 

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

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

这只是一个iPhone的工作方式,应用程序发送到后台,并保持状态,因为它是。我认为有办法实现你想要的,但这只是默认行为,并不是任何错误 – lascort 2015-01-26 20:00:40

回答

3

您可以订阅UIApplicationWillResignActiveNotification和调用方法的应用程序转到后台权之前,给VC设置为你想要的。这样,一旦他们重新打开应用程序,它应该在你想要的地方。

的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) 
} 
+0

他正在使用Swift,而不是Obj-C。 – Cesare 2015-01-26 20:12:10

+1

这是一回事......好吧,我会将它“翻译”成Swift。 – Armin 2015-01-26 20:14:23

+0

我应该在appDelegate还是特定的VC中调用这个方法? – user4363124 2015-01-27 00:26:05

相关问题