How to Implement a Table View in Your iOS App

By Neal Goldstein, Dave Wilson

iOS app programmers need to know how to implement table views. You may have worked with Table views before — but with static cells, all the work is done in the storyboard. Now it’s time to branch out on your own and understand what the storyboard does for you behind the scenes, as it were.

It’s a good thing to know how Table views work, because Table views are front and center in many apps that come with the iOS devices out of the box; they play a major role in many of the apps that you can download from the App Store. (Obvious examples: Almost all the views in the Settings, Mail, Music, and Contacts apps are Table views.)

Table views take on such a significant role because, in addition to displaying data, they can also serve as a way to navigate structured data.

If you take a look at an app such as Mail or Settings, you find that Table views present a scrollable list of items (or rows or entries) that may be divided into sections. A row can display text or images.

It may have an accessory such as a disclosure triangle, so that when you select a row, you may be presented with another Table view or with some other view that may display a web page or even controls such as buttons and Text fields.

It’s worth noting that iOS Table views only provide a single column of data — not the two-dimensional tables that you might build in a Numbers spreadsheet. The OS X Cocoa framework does provide a multi-column NSTableView class, but the IOS UITableView only supports a single column.

To kick off the Table view creation process, you first need to decide what you want to have happen when the user selects a particular row in the Table view of your app. As you saw with static cells, you can have virtually anything happen. You can display a web view as you do in Weather or even display another Table view.

In this case, however, the Destination View controller will be dismissed, and the user will find herself in the master view, ready to make another selection.

A Table view is an instance of the class UITableView, where each visible row of the table uses a UITableViewCell to draw its contents. Think of a Table view as the object that creates and manages the table structure, and the Table View cell as being responsible for displaying the content of a single cell of the table.