ios Swift-如何将标签栏和导航栏添加到单个视图控制器?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/31548909/
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-08-31 06:56:30  来源:igfitidea点击:

Swift-How do I add Tab Bar AND Navigation Bar to a single view controller?

iosxcodeswiftviewuinavigationbar

提问by Woohoopy

Using XCode, and either through Code or through the Storyboard, can someone please explain to me how to add both a Tab Bar and Nav Bar to my view controller while keeping both visible?

使用 XCode,并通过代码或故事板,有人可以向我解释如何将选项卡栏和导航栏添加到我的视图控制器,同时保持两者可见吗?

Thanks so much.

非常感谢。

回答by Ronald Martin

In your Storyboard, you should drag out a Tab Bar Controller and use that as the initial view controller. Then, you should embed each of the view controllers attached to the Tab Bar Controller inside Navigation Controllers (Editor menu: Embed In > Navigation Controller). Afterward, your Storyboard should look something like this:

在您的 Storyboard 中,您应该拖出一个 Tab Bar Controller 并将其用作初始视图控制器。然后,您应该将附加到标签栏控制器的每个视图控制器嵌入到导航控制器中(编辑器菜单:嵌入 > 导航控制器)。之后,您的 Storyboard 应如下所示:

enter image description here

在此处输入图片说明

The tab bar controller holds a tab bar and will manage switching between the other views attached to it, while the navigation controllers will place Navigation Bars at the top of each tab and help you manage navigation within the tab.

标签栏控制器包含一个标签栏,并将管理附加到它的其他视图之间的切换,而导航控制器将在每个标签的顶部放置导航栏,并帮助您管理标签内的导航。

回答by 72A12F4E

screenshot

截屏

I am assuming you want something like this. Here is how I did it in Interface Builder:

我假设你想要这样的东西。这是我在 Interface Builder 中的做法:

  1. Click your view controller.
  2. Editor -> Embed In -> Navigation Controller
  3. Reselect your view controller.
  4. Editor -> Embed In -> Tab Bar Controller
  5. Select the Navigation Controller
  6. Check the box next to Is Initial View Controller
  1. 单击您的视图控制器。
  2. Editor -> Embed In -> Navigation Controller
  3. 重新选择您的视图控制器。
  4. Editor -> Embed In -> Tab Bar Controller
  5. 选择导航控制器
  6. 选中旁边的框 Is Initial View Controller

Hope this helps!

希望这可以帮助!