Why not just set initial view controller for login screen like this?

家住魔仙堡 提交于 2019-12-02 20:44:04

问题


I've already read this and this questions. But I didn't understand why the code below is not enough. This just works. Do I need an else statement to set rootViewController for LoginViewController? Isn't it already set by Storyboard?

func application(application: UIApplication, willFinishLaunchingWithOptions launchOptions: [NSObject : AnyObject]?) -> Bool {
    if Settings.loggedIn {
        let mainStoryboard = UIStoryboard(name: "Main", bundle: NSBundle.mainBundle())
        let mainViewController = mainStoryboard.instantiateViewControllerWithIdentifier("MainViewController")
        self.window?.rootViewController = mainViewController
        self.window?.makeKeyAndVisible()
    }

    return true
}

In LoginController, should I set rootController of AppDelegate? Why not performSegue?

@IBAction func login(sender: AnyObject) {
    performSegueWithIdentifier("loginToMainSegue", sender: nil)    
}

Also why not performSegue to logout?

@IBAction func logout(sender: AnyObject) {
    performSegueWithIdentifier("MainToLoginSegue", sender: nil)    
}

来源:https://stackoverflow.com/questions/36767816/why-not-just-set-initial-view-controller-for-login-screen-like-this

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!