Search code examples
iosswiftuinavigationcontroller

Switching between two UINavigationControllers


Let's say I have two navigation stacks: one is for registration and login, the other is my main app.

On first-launch I'm going to show the registration and login stack and on completion transition to the main app stack. How can I switch between these two stacks smoothly?

Additionally, I'm going to show the main app stack and only present the login and register stack if the user signs out, so this one is clearer: just a self.present on the navigationcontroller.


Solution

  • You just need to set the navigation instance to

    (UIApplication.shared.delegate as! AppDelegate).window!.rootViewController = // main or register stack
    

    Actually you don't have to use 2 stacks it would be 1 and use it for push/pop appropriately , but while you do the login/home transitions do

    // this will clear all controllers from the stack and set only the assigned one 
    self.navigationController?.setViewControllers([mainVC/loginVC],animated:true)