How to hide UINavigationBar for my first view

I want to hide the UINavigationBar, which automatically loads the navigation project for the first view only, and I wonder how I can do this.

I am trying to do it like this:

//RootViewController.m

#import "mydelegate.h" //-- this is where the view controller is initialized //... - (void)viewDidLoad { [super viewDidLoad]; navigationController *navController = [[navigationController alloc] init]; [navigationController setNavigationBarHidden:YES animated:animated]; } //..... 

However, I am getting errors because I assume that I am not calling the navigationController from the delegate file properly, or it is simply impossible to name it as if you were using a method from another class.

Any help would be greatly appreciated.

+4
source share
3 answers

Are you accessing the correct instance of the UINavicationController? You can access the UINavigationController through self.navigationController from any UIViewController that has been added to its stack.

Otherwise, maybe this will help: iPhone hides the navigation bar only on the first page

+6
source

There are a couple of things.

  • You must access the navigation controller that your view controller represents using self.navigationController . Your code snippet creates a new UINavigationController; hiding this bar, you wonโ€™t get anything.
  • Instead of hiding the navigation bar in viewDidLoad , you should hide it in viewWillAppear: You can hide the navigation bar in viewDidLoad , and the navigation bar will be hidden when the view is initially presented, but if you want to click another view that displayed the navigation bar and click the back button, the navigation bar will remain visible.

Your viewWillAppear: should look something like this:

 - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; [self.navigationController setNavigationBarHidden:YES animated:animated]; } 

And the viewWillAppear: methods viewWillAppear: in other view controllers that you click on this navigation controller, should show or hide the navigation bar accordingly.

+8
source

iPhone hides the navigation bar only on the first page

Try this answer. He solved the problem for me.

I have a problem with the navigation bar. I can make him disappear, but I could not make him reappear when he needed it. This link explains how you can solve this problem by simply including it in viewWillAppear and turning it off in viewWillDisappear.

-1
source

All Articles