A view that presents data using rows arranged in a single column.
- iOS 2.0+
- Mac Catalyst 13.0+
- tvOS 9.0+
Table views on iOS display a single column of vertically scrolling content, divided into rows. Each row in the table contains one piece of your app’s content. For example, the Contacts app displays the name of each contact in a separate row, and the main page of the Settings app displays the available groups of settings. You can configure a table to display a single long list of rows, or you can group related rows into sections to make navigating the content easier.
Tables are commonly used by apps whose data is highly structured or organized hierarchically. Apps that contain hierarchical data often use tables in conjunction with a navigation view controller, which facilitates navigation between different levels of the hierarchy. For example, the Settings app uses tables and a navigation controller to organize the system settings.
UITable manages the basic appearance of the table, but your app provides the cells (
UITable objects) that display the actual content. The standard cell configurations display a simple combination of text and images, but you can define custom cells that display any content you want. You can also supply header and footer views to provide additional information for groups of cells.
Adding a Table View to Your Interface
To add a table view to your interface, drag a Table View Controller (
UITable) object to your storyboard. Xcode creates a new scene that includes both the view controller and a table view, ready for you to configure and use.
Table views are data driven, normally getting their data from a data source object that you provide. The data source object manages your app’s data and is responsible for creating and configuring the table’s cells. If the content of your table never changes, you can configure that content in your storyboard file instead.
For information about how to specify your table’s data, see Filling a Table with Data.
Saving and Restoring the Table's Current State
Table views support UIKit app restoration. To save and restore the table’s data, assign a nonempty value to the table view’s
restoration property. When its parent view controller is saved, the table view automatically saves the index paths for the currently selected and visible rows. If the table’s data source object adopts the
UIData protocol, the table stores the unique IDs that you provide for those items instead of their index paths.
For information about how to save and restore your app’s state information, see Preserving Your App's UI Across Launches.