How to hide a navigation bar from one particular view controller
Try this method inside a view controller:
// swift
self.navigationController?.setNavigationBarHidden(true, animated: true)
// objective-c
[self.navigationController setNavigationBarHidden:YES animated:YES];
More clarifications:
UINavigationController
has a property navigationBarHidden, that allows you to hide/show the navigation bar for the whole nav controller.
Let's look at the next hierarchy:
--UINavigationController
------UIViewController1
------UIViewController2
------UIViewController3
Each of three UIViewController has the same nav bar since they are in the UINavigationController. For example, you want to hide the bar for the UIViewController2 (actually it doesn't matter in which one), then write in your UIViewController2:
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[self.navigationController setNavigationBarHidden:YES animated:YES]; //it hides the bar
}
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
[self.navigationController setNavigationBarHidden:NO animated:YES]; // it shows the bar back
}
Swift 4:
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(true)
navigationController?.setNavigationBarHidden(true, animated: true)
}
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(true)
navigationController?.setNavigationBarHidden(false, animated: false)
}
This is worked for me:
Swift 4
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
navigationController?.setNavigationBarHidden(true, animated: false)
}
//reappears navigation bar on next page
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
navigationController?.setNavigationBarHidden(false, animated: true)
}
Use below one line code to hide Navigation bar in Swift3 and Swift4
navigationController?.setNavigationBarHidden(true, animated: true)
To show Navigation bar
navigationController?.setNavigationBarHidden(false, animated: true)