Swift: How to implement a login layout?

I have two different storyboards:

  • Mainstoryboard: SWrevealViewController (main part of the application)
  • Loginstoryboard: controller login / registration

Loginstoryboard should be used when the user is not logged in or the user is logged out. Then there should be a transition to the main stand.

How can I implement it in swift?

Waiting for your answers!
Jan

+4
source share
1 answer

You tried to switch yours rootViewControllertoapplication(_:didFinishLaunchingWithOptions:)

Assuming Mainstoryboardyours has rootViewController:

if userIsNotLoggedIn {
    let storyboard = UIStoryboard(name: "Loginstoryboard", bundle: nil)
    let loginController = storyboard.instantiateViewControllerWithIdentifier("LoginNavigationController") as UINavigationController
    window?.rootViewController = loginController
}

To switch view controllers after logging in, you can do this:

func loggedIn() {
    let storyboard = UIStoryboard(name: "Main", bundle: nil)
    let mainController = storyboard.instantiateViewControllerWithIdentifier("MainVC") as UIViewController
    let appDelegate = UIApplication.sharedApplication().delegate as AppDelegate
    appDelegate.window?.rootViewController = mainController
}
+7

All Articles