Reputation: 161
When i use that function i get sent back to my RootViewController but my navigation bar disappears. When i first run the app my navigation bar is working as intended, but when i login and then logout the navigation bar disappears. I am using Top bar "inferred" and using push Segues.
I tried to figuring it out by adding
navigationController?.navigationBar.hidden = false
to viewWillAppear
and viewDidAppear
function.
I also added this to the RootViewController but it did not work.
Is it my logout function that somehow remove the navigation bar or am i forgetting something?
Swift language preferred.
Upvotes: 1
Views: 4154
Reputation: 1
you might need to set the delegate as well. So in your viewWillAppear method add these lines. It works for me.
self.navigationController.navigationBar.hidden = NO;
[self.navigationItem setHidesBackButton:NO animated:YES];
self.navigationController.delegate = self;
Upvotes: 0
Reputation: 161
This question might not been the brightest but i fixed it by just simply making the logout function and logout button connect with the navigation controller view instead of the "main page" that have the navigation controller "embed in". When i connected the logout button with "main page" it did not load navigation controller settings and such, it only load one time since it is the initial view controller. I hope no one else will do the same mistake as me. :)
Upvotes: 1
Reputation: 2709
Maybe your root view controller is set to a controller that is displayed previous to the entry of your navigation controller? If so, upon entering the navigation controller you should set the navigation controller to the root view controller. Otherwise, I would recommend that when transitioning views if you wish to add them to the navigation stack that you use
self.navigationController?.pushViewController(viewController, animated: true)
And then popping back to a controller, you can either use
self.navigationController?.popToViewController(viewController, animated: true)
Or if the root view controller is in the navigation stack and it is this that you wish to return to then use
self.navigationController?.popToRootViewController(animated: true)
Of course the animated boolean being your own personal choice and the 'viewController' being the view controller you either want to push onto the navigation stack or pop back to. I have found that using push and pop to implement the navigation stack is a lot better than using push segues.
Upvotes: 0
Reputation: 616
You should never use
navigationController?.navigationBar.hidden = false
instead you should use
navigationController?.setNavigationBarHidden(false, animated: true)
Upvotes: 3