Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swift: How to implement a login storyboard?

I have two different storyboards:

  • Mainstoryboard: SWrevealViewController (major part of the app)
  • Loginstoryboard: Login/Register Controllers

The Loginstoryboard should be used when the user is not logged in or the user logged out. Then there should be a segue to the Mainstoryboard.

How could I implement it in swift?

Looking forward to your answers!
Jan

like image 721
Peter Avatar asked Mar 18 '23 06:03

Peter


1 Answers

Have you tried switching your rootViewController in application(_:didFinishLaunchingWithOptions:)

Assuming Mainstoryboard has your rootViewController:

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

To switch view controllers once logged 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
}
like image 61
Sean Avatar answered Mar 29 '23 04:03

Sean