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