C.Johns
C.Johns

Reputation: 10245

How to hide the UINavigationBar for my first view

I am wanting to hide the UINavigationBar that automatically loads with the Navigation project for the first view only and am wondering how I can make this work.

I have tries 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 guess I am not calling navigationController across from the delegate file properly or this is just not possible to call it like you would a method from another class.

Any help would be greatly appreciated.

Upvotes: 4

Views: 8565

Answers (3)

user3534908
user3534908

Reputation: 1

iPhone hide Navigation Bar only on first page

Try this answer. It solved the problem for me.

I was having the problem with the navigation bar as well. I could make it disappear, but I couldn't make it reappear when it needed to. This link explains how you can solve this problem, simply by turning it on in viewWillAppear, and off in viewWillDisappear.

Upvotes: -1

Jose Ibanez
Jose Ibanez

Reputation: 3345

There are a couple things wrong here.

  1. You should be accessing the navigation controller that's presenting your view controller by using self.navigationController. Your code snippet is creating a new UINavigationController; hiding that bar won't get you anything.
  2. 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 were to push another view that presented the navigation bar and hit the back button, the navigation bar would 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 in other view controllers you push on this navigation controller should show or hide the navigation bar appropriately.

Upvotes: 8

Kristofer Sommestad
Kristofer Sommestad

Reputation: 3061

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

Otherwise, maybe this'll help: iPhone hide Navigation Bar only on first page

Upvotes: 6

Related Questions