Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove navigation bar from main controller in Xcode?

I have a main view controller in Xcode 6 (program is in swift) on which I have a few buttons that lead to certain navigation controllers. When I test the app, the first time I see it it looks fine (without a navigation bar at the top). When I click on a button on main view controller, it shows the navigation controller I selected, everything acts perfectly again. The problem happens when I click on the bar button "back" on that nav controller in order for it to show me my main view controller again. When I'm back to the main view controller, there's a navigation bar at the top that isn't supposed to be there. I want my main view controller to have no navigation bar at the top. I tried to use push, modal and show segues to see if it might be the problem, but I still can't figure it out. Any thoughts on what might be happening?

like image 581
GuiGui23 Avatar asked Nov 27 '14 02:11

GuiGui23


2 Answers

Sounds like you need to re-hide your navigation bar. To do that, add:

self.navigationController?.navigationBarHidden = true

to the viewWillAppear of whatever view controller for which you'd like to hide the nav bar.


Updated for Swift 3:

self.navigationController?.isNavigationBarHidden = true
like image 200
Lyndsey Scott Avatar answered Oct 31 '22 23:10

Lyndsey Scott


In mainViewController, write code to hide navigation bar in viewWillAppear method. in Objective-C

-(void)viewWillAppear:(BOOL)animated
{
   [super viewWillAppear:YES];
   [[self navigationController] setNavigationBarHidden:YES animated:NO];
}
like image 30
ObjC Avatar answered Oct 31 '22 22:10

ObjC