简体   繁体   中英

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?

Thanks so much.

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:

在此输入图像描述

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:

  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

Hope this helps!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM