codejunkie
codejunkie

Reputation: 1122

UINavigation Controller hiding navbar

using xcode 4.2 and iOS 5 and have nav bar on root controller and four other views (inc UITable view) all i want is to hide nav bar in first root view controller and show in all other views...

Tried following

[self.navigationController setNavigationBarHidden:YES animated:animated];

No luck any ideas?

Upvotes: 2

Views: 1558

Answers (2)

Avinash651
Avinash651

Reputation: 1399

You can hide this by using this code

self.navigationController.navigationBar.hidden = YES;

Use this code in view did load

Upvotes: 1

sergio
sergio

Reputation: 69027

Use this code in your root controller (or all of your view controllers that you want to have a hidden navigation bar. see [1] though) in order to hide/show the navigation bar according to what you are aiming at:

- (void)viewDidLoad {
   ...
  [self.navigationController setNavigationBarHidden:YES animated:NO];
   ...
}

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

 - (void)viewWillDisappear:(BOOL)animated {
    [self.navigationController setNavigationBarHidden:NO animated:animated];
    ...
 }

This is just a possible solution. You could well leave viewWillDisappear undefined in your non-root controllers and define viewWillAppear in your root controller... as you see it most convenient for you.

[1] Hiding the navigation bar in anything but the root controller makes it possible to get stuck in the middle of your navigation hierarchy. Also it is against intuitive navigation in an iOS app to suddenly hide the navigation bar for anything else than the root view.)

Upvotes: 3

Related Questions