My navigation bar is showing up in storyboard but

2019-07-30 07:47发布

问题:

When trying to add a navigation bar for searching on the left button and eventually a setting button on the right bar button, the bar isn't showing up in the simulator. Screenshot

Should I be using a regular toolbar like the temporary one I have on the bottom? I'd prefer the search button for loading new addresses, and settings for the obvious, but then I want buttons that serve as navigations for moving from tab to tab. Should I simply implement a search bar above the map view and a settings button on the right? I'm new to xcode and it's kicking my ass.

EDIT: After changing the hidden to "self.navigationController?.setToolbarHidden(false, animated: true)" the toolbar appeared but at the bottom below the current toolbar with zoom and type buttons. So it looks as if it thinks it's a toolbar and only wants to put it at the bottom?

回答1:

self.navigationController.navigationBar.hidden = false;

Use above code to show navigation bar.



回答2:

I Believe you might be aligning the top of the Map View to the top of the top layout guide, if this is the case your toobar might be hidden behind the map view. I would change that constraint that constraint in the map view and use "vertical spacing" to the tool bar in the top and give it a value of 0.



回答3:

Don't add navigation bar manually If you are adding. You will get Your navigation bar with your navigation controller. In your viewWillAppear() put the line of code self.navigationController?.setNavigationBarHidden(false, animated: true).



回答4:

Swift 4 solution

Add this code to your ViewController:

   override func viewWillAppear(_ animated: Bool) {
        self.navigationController?.navigationBar.isHidden = false
    }