Lesson 16

Table Views

A table view is a user interface component used to present a list of items to the user. Table views are instances of the UITableView class and are part of the UIKit framework. Table views are one of the most versatile user interface components in UIKit and can be found in several apps, including Apple's own contacts, and mail applications. In this lesson, you learn to use table views in your applications.

Table View Appearance

A table view allows you to present a single column of values. Each value is presented vertically in its own row. A user can scroll through the rows vertically. Vertical scrolling is automatically managed by the table view and is enabled when the number of rows exceed the visible height of the table view.

Each row in a table view is an instance of another UIKit class called UITableViewCell. The table view has a mechanism in place that allows you to reuse table view cells instead of creating a new one for each row.

Data in table views are presented in sections. Sections are numbered from zero and run vertically down the table (see Figure 16.1).

Screenshot of iOS device with data in different section of table view.

Figure 16.1

Each section can have an optional header and footer. The default table view has just one section with no visible header or footer (see Figure 16.2).

Screenshot of iOS device with data in table views with no header or footer.

Figure 16.2

Rows within ...

Get Swift iOS 24-Hour Trainer 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.