122

I have a universal app, and on the iPad version I'm using UISplitViewController to create an interface similar to the Mail app.

I was having trouble pushing new Detail views, so I decided to use a UINavigationController so I could just push and pop views as needed. However, I do not want to use the navigation view or a toolbar. But no matter what I do, I can't hide the navigation bar.

I've tried unchecking "Shows Navigation Bar" in IB, and I've also tried setting:

[self.navigationController setNavigationBarHidden:YES];

in the viewDidLoad/viewDidAppear/viewWillAppear. I've also tried it in each of the views that will be pushed. Nothing works.

Is there something I'm missing here? Is it possible to have a UINavigationController without a toolbar or navigation bar?

KlimczakM
  • 12,576
  • 11
  • 64
  • 83
DOOManiac
  • 6,066
  • 8
  • 44
  • 67

6 Answers6

201

You should be able to do the following:

self.navigationController.navigationBar.isHidden = true //Swift 5

where self.navigationController is (obviously) an instance of UINavigationController. Seems to work for me, but I only briefly tested it before posting this.

iluvatar_GR
  • 1,017
  • 13
  • 19
Ashwin
  • 2,317
  • 1
  • 15
  • 5
  • 2
    So, in your case, self.navigationController.navigationBar.hidden = YES; – Ashwin Apr 23 '11 at 18:17
  • 4
    That did it! Though I'll add that I was able to simply check the Hidden box for the Nagivation toolbar in IB instead of doing it through code. Thanks! – DOOManiac Apr 23 '11 at 20:23
  • 1
    Yeah, sorry about that. I should have picked up on the fact that you were using IB and mentioned the Hidden box instead of using code. I've recently been on a kick of creating all my interfaces entirely programmatically without .xib files, so went straight to that for my answer. – Ashwin Apr 24 '11 at 03:45
  • 5
    I call this is in viewwillapear in my view controller like this `- (void)viewWillAppear:(BOOL)animated { self.navigationController.navigationBar.hidden = YES; } ` and it works – Ali Jun 27 '12 at 19:23
  • 3
    The navBar is hidden but my view controller screen does not expand to the full screen – ArdenDev Oct 21 '14 at 21:33
  • If you wanted to do this entirely in Storyboards, select the navController in your Storyboard, open the Identity Inspector and add a User Defined Runtime Attribute key of `navigationBar.hidden` with a type of Boolean and ticked. – Scott Fister May 05 '15 at 19:04
  • This trick does forbids the following views to move up & down when bar is hidden or shown. – tounaobun Oct 18 '16 at 07:11
  • It's better to pass `animated` to the navigation controller's method that can control it. For example in `viewWillAppear:` method: `[self.navigationController setNavigationBarHidden:YES animated:animated];` Otherwise it can become a bit glitchy. – Michal Cichon Jul 06 '18 at 15:07
40

In Xcode 4.3.2:

  1. Select the navigation controller in the storyboard
  2. Select the Attributes Inspector in the (right) Utilities panel
  3. Under the Navigation Controller category you have two check boxes:

    [] Shows Navigation Bar

    [] Shows Toolbar

Worked for me...

Avner
  • 5,791
  • 2
  • 29
  • 33
40

If you want no navigation bar, and you want the content to be adjusted up to where the navigation bar normally would be, you should use

self.navigationController.navigationBarHidden = YES;

This gives you a result like this:

enter image description here

Whereas self.navigationController.navigationBar.hidden = YES; gives you a space where the navigationBar should be. Like this:

enter image description here

HalR
  • 11,411
  • 5
  • 48
  • 80
  • Very nice distinction on the difference in results with iOS 6. As of IOS 7, it appears that the space is removed, but I'll wait for more people to verify that is the case. – Alex Zavatone Aug 11 '14 at 16:09
8

Swift 4

I hide it in viewWillAppear

     override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)

        self.navigationController?.isNavigationBarHidden = true;
    }

Then you can put it back when you push a segue (if you want to have the back button on the next view)

     override func prepare(for segue: UIStoryboardSegue, sender: Any?) 
     {
        self.navigationController?.isNavigationBarHidden = false;
     }
user1296082
  • 171
  • 1
  • 3
3

Swift 3 Programmatically

self.navigationController.isNavigationBarHidden = true

or

self.navigationController.navigationBar.isHidden = true

Note: I didn't see a difference between these two approaches testing on iOS 10.

Mobile Dan
  • 6,444
  • 1
  • 44
  • 44
1

All these answers still leave a space at the top for the status bar - add this line to remove that as well:

navController.navigationBar.isHidden = true
navController.accessibilityFrame = CGRect.zero
Cbas
  • 6,003
  • 11
  • 56
  • 87