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 O’Reilly online learning.

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