26

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.

Woohoopy
  • 303
  • 1
  • 3
  • 9

2 Answers2

64

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.

Ronald Martin
  • 4,278
  • 3
  • 27
  • 32
11

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!

72A12F4E
  • 1,744
  • 1
  • 14
  • 28
  • 7
    With this you have the same navigation bar for both view controllers. – pommes Oct 30 '15 at 18:19
  • 3
    True, and if you need them to be different, I would recommend [Ronald Martin's answer](http://stackoverflow.com/a/31549190/4099162). In an application I was creating, I had several custom attributes on my navbar that were a pain to re-create, and I found it easier to just change the title of the nav. To each their own – 72A12F4E Dec 02 '15 at 15:31
  • Does there anyway to set title to NavigationItem? – Raymond Liao Oct 18 '16 at 02:08
  • my app has start with one page and then push to the tab bar controller so I embed In first page to navigation Bar But when in the tab Bar I click to go to another page I can't see the navigation Bar – Saeed Rahmatolahi Feb 03 '18 at 06:16
  • @72A12F4E How do I do this programmatically – N. Der May 20 '19 at 02:34