Protocol

UITableViewDelegate

Methods for managing selections, configuring section headers and footers, deleting and reordering cells, and performing other actions in a table view.

Declaration

@protocol UITableViewDelegate

Overview

Use the methods of this protocol to manage the following features:

  • Create and manage custom header and footer views.

  • Specify custom heights for rows, headers, and footers.

  • Provide height estimates for better scrolling support.

  • Indent row content.

  • Respond to row selections.

  • Respond to swipes and other actions in table rows.

  • Support editing the table's content.

The table view specifies rows and sections using NSIndexPath objects. For information about how to interpret row and section indexes, see Specifying the Location of Rows and Sections.

Topics

Configuring Rows for the Table View

- tableView:willDisplayCell:forRowAtIndexPath:

Tells the delegate the table view is about to draw a cell for a particular row.

- tableView:indentationLevelForRowAtIndexPath:

Asks the delegate to return the level of indentation for a row in a given section.

- tableView:shouldSpringLoadRowAtIndexPath:withContext:

Called to let you fine tune the spring-loading behavior of the rows in a table.

Responding to Row Selections

- tableView:willSelectRowAtIndexPath:

Tells the delegate that a specified row is about to be selected.

- tableView:didSelectRowAtIndexPath:

Tells the delegate that the specified row is now selected.

- tableView:willDeselectRowAtIndexPath:

Tells the delegate that a specified row is about to be deselected.

- tableView:didDeselectRowAtIndexPath:

Tells the delegate that the specified row is now deselected.

Providing Custom Header and Footer Views

- tableView:viewForHeaderInSection:

Asks the delegate for a view object to display in the header of the specified section of the table view.

- tableView:viewForFooterInSection:

Asks the delegate for a view object to display in the footer of the specified section of the table view.

- tableView:willDisplayHeaderView:forSection:

Tells the delegate that the table is about to display the header view for the specified section.

- tableView:willDisplayFooterView:forSection:

Tells the delegate that the table is about to display the footer view for the specified section.

Providing Header, Footer, and Row Heights

- tableView:heightForRowAtIndexPath:

Asks the delegate for the height to use for a row in a specified location.

- tableView:heightForHeaderInSection:

Asks the delegate for the height to use for the header of a particular section.

- tableView:heightForFooterInSection:

Asks the delegate for the height to use for the footer of a particular section.

UITableViewAutomaticDimension

A constant representing the default value for a given dimension.

Estimating Heights for the Table's Content

- tableView:estimatedHeightForRowAtIndexPath:

Asks the delegate for the estimated height of a row in a specified location.

- tableView:estimatedHeightForHeaderInSection:

Asks the delegate for the estimated height of the header of a particular section.

- tableView:estimatedHeightForFooterInSection:

Asks the delegate for the estimated height of the footer of a particular section.

Managing Accessory Views

- tableView:accessoryTypeForRowWithIndexPath:

Asks the delegate for the type of standard accessory view to use as a disclosure control for the specified row.

Deprecated
- tableView:accessoryButtonTappedForRowWithIndexPath:

Tells the delegate that the user tapped the detail button for the specified row.

Responding to Row Actions

- tableView:leadingSwipeActionsConfigurationForRowAtIndexPath:

Returns the swipe actions to display on the leading edge of the row.

- tableView:trailingSwipeActionsConfigurationForRowAtIndexPath:

Returns the swipe actions to display on the trailing edge of the row.

- tableView:shouldShowMenuForRowAtIndexPath:

Asks the delegate if the editing menu should be shown for a certain row.

Deprecated
- tableView:canPerformAction:forRowAtIndexPath:withSender:

Asks the delegate if the editing menu should omit the Copy or Paste command for a given row.

Deprecated
- tableView:performAction:forRowAtIndexPath:withSender:

Tells the delegate to perform a copy or paste operation on the content of a given row.

Deprecated
- tableView:editActionsForRowAtIndexPath:

Asks the delegate for the actions to display in response to a swipe in the specified row.

Deprecated

Managing Table View Highlights

- tableView:shouldHighlightRowAtIndexPath:

Asks the delegate if the specified row should be highlighted.

- tableView:didHighlightRowAtIndexPath:

Tells the delegate that the specified row was highlighted.

- tableView:didUnhighlightRowAtIndexPath:

Tells the delegate that the highlight was removed from the row at the specified index path.

Editing Table Rows

- tableView:willBeginEditingRowAtIndexPath:

Tells the delegate that the table view is about to go into editing mode.

- tableView:didEndEditingRowAtIndexPath:

Tells the delegate that the table view has left editing mode.

- tableView:editingStyleForRowAtIndexPath:

Asks the delegate for the editing style of a row at a particular location in a table view.

- tableView:titleForDeleteConfirmationButtonForRowAtIndexPath:

Changes the default title of the delete-confirmation button.

- tableView:shouldIndentWhileEditingRowAtIndexPath:

Asks the delegate whether the background of the specified row should be indented while the table view is in editing mode.

Reordering Table Rows

- tableView:targetIndexPathForMoveFromRowAtIndexPath:toProposedIndexPath:

Asks the delegate to return a new index path to retarget a proposed move of a row.

Tracking the Removal of Views

- tableView:didEndDisplayingCell:forRowAtIndexPath:

Tells the delegate that the specified cell was removed from the table.

- tableView:didEndDisplayingHeaderView:forSection:

Tells the delegate that the specified header view was removed from the table.

- tableView:didEndDisplayingFooterView:forSection:

Tells the delegate that the specified footer view was removed from the table.

Managing Table View Focus

- tableView:canFocusRowAtIndexPath:

Asks the delegate whether the cell at the specified index path is itself focusable.

- tableView:shouldUpdateFocusInContext:

Asks the delegate whether the focus update specified by the context is allowed to occur.

- tableView:didUpdateFocusInContext:withAnimationCoordinator:

Tells the delegate that a focus update specified by the context has just occurred.

- indexPathForPreferredFocusedViewInTableView:

Asks the delegate for the table view’s index path for the preferred focused view.

Relationships

Conforming Types

See Also

Table Management

Estimating the Height of a Table's Scrolling Area

Provide height estimates for your table view’s headers, footers, and rows to ensure that scrolling accurately reflects the size of your content.

UITableViewController

A view controller that specializes in managing a table view.

UITableViewFocusUpdateContext

A context object that provides information relevant to a specific focus update from one view to another.

Beta Software

This documentation contains preliminary information about an API or technology in development. This information is subject to change, and software implemented according to this documentation should be tested with final operating system software.

Learn more about using Apple's beta software