A view controller that specializes in managing a table view.


class UITableViewController : UIViewController


Subclass UITableViewController when your interface consists of a table view and little or no other content. Table view controllers already adopt the protocols you need to manage your table view's content and respond to changes. In addition, UITableViewController implements the following behaviors:

  • It automatically loads the table view archived in a storyboard or nib file. Access the table view using the tableView property.

  • It sets the data source and the delegate of the table view to self.

  • It implements the viewWillAppear(_:) method and automatically reloads the data for its table view on first appearance. It clears its selection (with or without animation, depending on the request) every time the table view is displayed; you can disable this behavior by changing the value in the clearsSelectionOnViewWillAppear property.

  • It implements the viewDidAppear(_:) method and automatically flashes the table view's scroll indicators when it first appears.

  • It implements the setEditing(_:animated:) method and automatically toggles the edit mode of the table when the user taps an Edit|Done button in the navigation bar.

  • It automatically resizes its table view to accommodate the appearance or disappearance of the onscreen keyboard.

Create a custom subclass of UITableViewController for each table view that you manage. When you initialize the table view controller, you must specify the style of the table view (plain or grouped). You must also override the data source and delegate methods required to fill your table with data. You may override loadView() or any other superclass method, but if you do, be sure to invoke the superclass implementation of the method, usually as the first method call.


Creating the Table View Controller

init(style: UITableView.Style)

Initializes a table-view controller to manage a table view of a given style.

Getting the Table View

var tableView: UITableView!

Returns the table view managed by the controller object.

Configuring the Table Behavior

var clearsSelectionOnViewWillAppear: Bool

A Boolean value indicating if the controller clears the selection when the table appears.

Refreshing the Table View

var refreshControl: UIRefreshControl?

The refresh control used to update the table contents.

See Also

Content View Controllers

Displaying and Managing Views with a View Controller

Build a view controller in storyboards, configure it with custom views, and fill those views with your app’s data.

Showing and Hiding View Controllers

Display view controllers using different techniques, and pass data between them during transitions.

class UIViewController

An object that manages a view hierarchy for your UIKit app.

class UICollectionViewController

A view controller that specializes in managing a collection view.

protocol UIContentContainer

A set of methods for adapting the contents of your view controllers to size and trait changes.