6.3. Adding a Tab Bar Controller to a Storyboard

Problem

You want to create an application based on a tab bar controller using storyboards.

Solution

Create a single-view application in Xcode and embed your first view controller in a tab bar controller. After that, drag and drop more view controllers onto your storyboards and establish a connection between them and the array of view controllers inside your tab bar controller.

Discussion

So you’ve created a single-view application project in Xcode and you want to start using tab bar controllers in your app. In order to achieve that, simply follow these steps:

  1. Select the view controller on your storyboard in Interface Builder. From the Editor menu, choose Embed In, and then choose Tab Bar Controller, as shown in Figure 6-9.

Embedding your root view controller in a tab bar controller

Figure 6-9. Embedding your root view controller in a tab bar controller

  1. Now, from the Object Library in Interface Builder, drag and drop a new instance of View Controller onto your storyboard.

  2. Hold down the Ctrl key on your keyboard and drag and drop your mouse from within the tab bar controller onto the new view controller that you created (Figure 6-10), and in the dialog that appears on the screen, choose view controllers under the Relationship Segues section (Figure 6-11).

Connecting your view controller to the tab bar controller

Figure 6-10. Connecting your view controller to the ...

Get iOS 7 Programming Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.