xcode 我的导航栏显示在故事板中,但不在模拟器中

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/36563012/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 08:43:08  来源:igfitidea点击:

My navigation bar is showing up in storyboard but not in the simulator

iosiphonexcodeswiftuinavigationbar

提问by ggworean

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.

我应该使用像底部临时工具栏那样的常规工具栏吗?我更喜欢用于加载新地址的搜索按钮,以及用于明显设置的按钮,但随后我想要用作从选项卡移动到选项卡的导航的按钮。我应该简单地在地图视图上方实现一个搜索栏并在右侧实现一个设置按钮吗?我是 xcode 的新手,这让我很不爽。

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?

编辑:将隐藏更改为“self.navigationController?.setToolbarHidden(false,animated: true)”后,工具栏出现但位于当前工具栏下方的底部,带有缩放和类型按钮。所以它看起来好像它是一个工具栏,只想把它放在底部?

回答by Mahendra

self.navigationController.navigationBar.hidden = false;

Use above code to show navigation bar.

使用上面的代码来显示导航栏。

回答by Daniel Orme?o

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.

我相信您可能会将地图视图的顶部与顶部布局指南的顶部对齐,如果是这种情况,您的工具栏可能隐藏在地图视图的后面。我会在地图视图中更改该约束,并在顶部的工具栏中使用“垂直间距”并将其值设为 0。

回答by Ketan Parmar

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).

如果要添加,请不要手动添加导航栏。您将获得带有导航控制器的导航栏。在你viewWillAppear()把代码行self.navigationController?.setNavigationBarHidden(false, animated: true)

回答by Sébastien REMY

Swift 4 solution

斯威夫特 4 解决方案

Add this code to your ViewController:

将此代码添加到您的 ViewController:

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