GuiGui23 GuiGui23 - 1 year ago 139
iOS Question

Remove navigation bar from main controller in Xcode?

I have a main view controller in Xcode 6 (program is in swift) on which I have a few buttons that lead to certain navigation controllers. When I test the app, the first time I see it it looks fine (without a navigation bar at the top). When I click on a button on main view controller, it shows the navigation controller I selected, everything acts perfectly again. The problem happens when I click on the bar button "back" on that nav controller in order for it to show me my main view controller again. When I'm back to the main view controller, there's a navigation bar at the top that isn't supposed to be there. I want my main view controller to have no navigation bar at the top. I tried to use push, modal and show segues to see if it might be the problem, but I still can't figure it out. Any thoughts on what might be happening?

Answer Source

Sounds like you need to re-hide your navigation bar. To do that, add:

self.navigationController?.navigationBarHidden = true

to the viewWillAppear of whatever view controller for which you'd like to hide the nav bar.

Updated for Swift 3:

self.navigationController?.isNavigationBarHidden = true
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download