简体   繁体   English

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

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

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,通过代码或通过故事板,有人可以向我解释如何将Tab Bar和Nav Bar添加到我的视图控制器同时保持可见?

Thanks so much. 非常感谢。

In your Storyboard, you should drag out a Tab Bar Controller and use that as the initial view controller. 在Storyboard中,您应该拖出一个Tab Bar 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应该是这样的:

在此输入图像描述

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. 标签栏控制器包含一个标签栏,并将管理与其连接的其他视图之间的切换,而导航控制器将导航栏放置在每个标签的顶部,并帮助您管理标签内的导航。

截图

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 选中Is Initial View Controller旁边的框

Hope this helps! 希望这可以帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用标签栏项添加导航栏以查看控制器 - How to add Navigation bar to view controller with tab bar item 如何立即隐藏单个视图控制器上的导航栏? - How do I instantly hide the navigation bar on a single view controller? 使用 Tab Bar Controller Swift 在导航栏中添加新的栏按钮 - Add new bar button in Navigation Bar with a Tab Bar Controller Swift 如何快速隐藏嵌入在导航堆栈中的视图控制器中的选项卡栏? - how to hide tab bar in the view controller that embedded in the navigation stack in swift? 如何在 Swift 中向 Tab Bar Controller 添加表视图控制器 - How to add a table view Controller to Tab Bar Controller in Swift 如何在swift中设置标签栏控制器的默认选项卡 - How do I set the default tab for tab bar controller in swift 将标签栏添加到导航控制器 - Add Tab Bar to Navigation Controller 如何在导航栏、标签栏、视图控制器之间传递数据 - How to pass data among Navigation bar, Tab bar, View Controller 如何在标签栏控制器中从一个视图控制器切换到另一个视图控制器并保留标签栏? - How within a tab bar controller do I segue from one view controller to another and retain the tab bar? 如何使用Swift在子视图中添加选项卡栏和导航栏? - How to add Tab bar and navigation bar in subviews using swift?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM