Reputation: 1
I'm facing a slight problem with my UINavigationBar.
I have a an Initial Root View Controller (ViewController) followed by 2 View Controllers (LoginMRNViewController and LoginOTPViewController) that are used to login the user with One Time Password. I also have NavigationController used to navigate the user to his/her homepage after logging in. In the homepage, I have a (Logout) button, that logs out the user with Firebase and navigates him/her to the Initial Root View Controller (ViewController).
The UINavigationBar works like a charm, however, whenever the user logout, he is navigated to the Initial Root View Controller (ViewController) but the UINavigationBar completely disappears!
My logout function:
@IBAction func logoutPressed(_ sender: Any) {
do {
try Auth.auth().signOut()
self.performSegue(withIdentifier: "goToLoginScreen", sender: self)
print ("User logged out")
} catch let error {
print ("Failed to logout with error", error)
}
}
Here's how my Storyboard looks like.
EDIT:
I tried to put this in my Initial Root View Controller (ViewController) and the other 2 View Controllers (LoginMRNViewController and LoginOTPViewController) in the ViewWillAppear method, but unfortunately it did not work.
self.navigationController?.setNavigationBarHidden(false, animated: false)
tabBarController?.tabBar.isHidden = false
Here's how my updated Storyboard look like.
Upvotes: 0
Views: 132
Reputation: 1046
Don't add the another NavigationController to hide back button.
Add navigationItem.setHidesBackButton(true, animated: true)
to hide back button.
Then on logout simply add self.navigationController?.popToRootViewController(animated: true)
It should work as expected.
Upvotes: 0