ChatGPT解决这个技术问题 Extra ChatGPT

UINavigationController without navigation bar?

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?

What is the superclass of the class self is an instance of?

i
iluvatar_GR

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.


So, in your case, self.navigationController.navigationBar.hidden = YES;
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!
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.
I call this is in viewwillapear in my view controller like this - (void)viewWillAppear:(BOOL)animated { self.navigationController.navigationBar.hidden = YES; } and it works
The navBar is hidden but my view controller screen does not expand to the full screen
A
Avner

In Xcode 4.3.2:

Select the navigation controller in the storyboard Select the Attributes Inspector in the (right) Utilities panel Under the Navigation Controller category you have two check boxes: [] Shows Navigation Bar [] Shows Toolbar

Worked for me...


H
HalR

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:

https://i.stack.imgur.com/UZbHX.png

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

https://i.stack.imgur.com/QuHcf.png


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.
u
user1296082

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;
     }

M
Mobile Dan

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.


C
Cbas

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