Reputation: 1449
I have a login view controller that, upon successful login, pushes my user to another view controller (ViewControllerB). That being said, ViewControllerB is embedded in a UINavigationController that I've already formatted with a menu button.
Because I'm using a push segue from the login view controller, this segue causes my UINavigationBar to be covered with a blank nav bar and a back button (not cool). That said, I tried to hide the navigation controller from login view controller with the following code:
loginviewcontroller.m
- (void) viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[self.navigationController setNavigationBarHidden:YES animated:animated];
}
When I do this, the unwanted navigation bar with the back button covering my other nav bar is removed! Great. However when I then navigate to other screens, my nav bar remains hidden (and I want it to appear once my user makes it past ViewControllerB).
I tried using a modal segue upon successful login, but of course, that keeps me from being able to navigate to other screens with segues upon login.
Any idea how I can go about doing this?
Upvotes: 3
Views: 2481
Reputation: 2247
swift 3
override func viewWillAppear(_ animated: Bool) {
//for hide navigation bar in current view
super.viewWillAppear(animated)
self.navigationController?.setNavigationBarHidden(true, animated: animated)
}
override func viewWillDisappear(_ animated: Bool) {
//for unhide in navigation bar in next/previous view
super.viewWillDisappear(animated)
self.navigationController?.setNavigationBarHidden(false, animated: animated)
}
Upvotes: 0
Reputation: 176
You should embedin UINavigationController from your first Viewcontroller or your loginViewController and at this ViewController you will hide the navigation bar and for your next viewController you can unhide the navigationbar. It has worked for me.
Upvotes: 1
Reputation: 1678
Add this:
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
[self.navigationController setNavigationBarHidden:NO animated:animated];
}
Upvotes: 2