4

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.

C.Johns
  • 10,185
  • 20
  • 102
  • 156

3 Answers3

8

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.

Jose Ibanez
  • 3,325
  • 3
  • 28
  • 33
6

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

Community
  • 1
  • 1
Kristofer Sommestad
  • 3,061
  • 27
  • 39
  • Ah Right! This worked :) thankyou, I need to read how things are added to the navigation stack. [self.navigationController setNavigationBarHidden:YES animated:NO]; – C.Johns Aug 23 '11 at 21:12
  • No problems. Recommend reading through the Overview and Tasks sections of the Apple docs: http://developer.apple.com/library/ios/#documentation/UIKit/Reference/UINavigationController_Class/Reference/Reference.html – Kristofer Sommestad Aug 23 '11 at 21:17
  • cheers, will check it out now.. This is when I first started out in ios development I read a crap load of stuff off apple docs but at the time didn't understand a whole lot of it.. so maybe nows a good time to go back and refresh. – C.Johns Aug 23 '11 at 21:30
-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.

Community
  • 1
  • 1
  • Hello and welcome to Stackoverflow. Please read the guidelines for good answers: http://stackoverflow.com/questions/how-to-answer. One of the rules is to add context to links, instead of just pasting them. You should provide an answer that is valid without the need for the user to navigate to another side, but might wish to do so for more detail on the answer. That becomes a bigger problem when the links for some reason become invalid. – bitoiu Apr 15 '14 at 12:59