Search code examples
iosswiftuinavigationcontroller

Swift 4: NavigationController Not Showing Bar on Subsequent Pages


I embedded the LoginVC a NavigationController and on log-in, push the user to SwitchboardVC.

If the user is already logged in, I bypass the Login Screen with this code in the AppDelegate in didFinishLaunchingWithOptions:

if Auth.auth().currentUser != nil
{
    let mainStoryBoard: UIStoryboard = UIStoryboard(name:"Main", bundle:nil)
    let nextView: SwitchboardVC = mainStoryBoard.instantiateViewController(withIdentifier: "SwitchboardVC") as! SwitchboardVC
    self.window?.rootViewController = nextView
}

When I have to login, the NavigationBar shows on all screens but if I am already logged in, the navigation bar is missing on all other screens.

I haven't been able to find a solution on Google yet but I am assuming that I am not searching for the correct term.

Any help is greatly appreciated


Solution

  • I believe it is because you are setting your root as the newView rather than pushing the newView from the navigationController, which would add it to the navigation stack and keep the bar at the top. For the navigation hierarchy here is some reading: https://medium.com/@strawb3rryx7/swift-the-hierarchy-of-uinavigationcontroller-programmatically-91631990f495