Lesson 18

Tab Bars and Toolbars

Lesson 15 discussed navigation controllers, which allowed your application to present a hierarchy of views one at a time. A tab bar controller, on the other hand, allows you to display multiple view controllers at the same time (see Figure 18.1).

Screenshot of iOS device with tab bar controller, with values listed under different heads and icons for Top Rated in blue and About at the bottom.

Figure 18.1

Navigation controllers are well suited to a hierarchical app structure, where users navigate one screen at a time to reach their destination. A tab bar controller is handy when it comes to creating a flat app structure where users can navigate directly from one primary category to another (see Figure 18.2). Examples of such apps include the Clock and the App store apps on iOS devices.

Flowcharts of Hierarchial structure, works well with navigation controllers and Flat structure, works well with tab bar controllers .

Figure 18.2

View controllers provide the content of tabs within a tab bar controller. It is quite common to combine tab bar controllers and navigation controllers to create an app that provides the best of both. The tab bar sits at the top of the view controller hierarchy and some of the tabs could have a navigation controller within them that provides a drill-down interface for the content within that tab. The Phone app on the iPhone is an example of such an app, with the Contacts tab containing a navigation controller that allows you to drill down into a contact's details.

A tab bar represents a single ...

Get Swift iOS 24-Hour Trainer now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.