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

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


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:

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.


screenshot

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!