Protocol

UITableViewDelegate

The delegate of a UITableView object must adopt the UITableViewDelegate protocol. Optional methods of the protocol allow the delegate to manage selections, configure section headings and footers, help to delete and reorder cells, and perform other actions.

Overview

Many methods of the UITableViewDelegate protocol take NSIndexPath objects as parameters and return values. UIKit declares a category on NSIndexPath that enables you to get the represented row index (row property) and section index (section property), and to construct an index path from a given row index and section index (init(row:section:) method). Because rows are located within their sections, you usually must evaluate the section index number before you can identify the row by its index number.

Symbols

Configuring Rows for the Table View

func tableView(UITableView, heightForRowAt: IndexPath)

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

func tableView(UITableView, estimatedHeightForRowAt: IndexPath)

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

func tableView(UITableView, indentationLevelForRowAt: IndexPath)

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

func tableView(UITableView, willDisplay: UITableViewCell, forRowAt: IndexPath)

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

Managing Accessory Views

func tableView(UITableView, editActionsForRowAt: IndexPath)

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

func tableView(UITableView, accessoryButtonTappedForRowWith: IndexPath)

Tells the delegate that the user tapped the accessory (disclosure) view associated with a given row.

Managing Selections

func tableView(UITableView, willSelectRowAt: IndexPath)

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

func tableView(UITableView, didSelectRowAt: IndexPath)

Tells the delegate that the specified row is now selected.

func tableView(UITableView, willDeselectRowAt: IndexPath)

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

func tableView(UITableView, didDeselectRowAt: IndexPath)

Tells the delegate that the specified row is now deselected.

Modifying the Header and Footer of Sections

func tableView(UITableView, viewForHeaderInSection: Int)

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

func tableView(UITableView, viewForFooterInSection: Int)

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

func tableView(UITableView, heightForHeaderInSection: Int)

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

func tableView(UITableView, estimatedHeightForHeaderInSection: Int)

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

func tableView(UITableView, heightForFooterInSection: Int)

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

func tableView(UITableView, estimatedHeightForFooterInSection: Int)

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

func tableView(UITableView, willDisplayHeaderView: UIView, forSection: Int)

Tells the delegate that a header view is about to be displayed for the specified section.

func tableView(UITableView, willDisplayFooterView: UIView, forSection: Int)

Tells the delegate that a footer view is about to be displayed for the specified section.

Editing Table Rows

func tableView(UITableView, willBeginEditingRowAt: IndexPath)

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

func tableView(UITableView, didEndEditingRowAt: IndexPath?)

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

func tableView(UITableView, editingStyleForRowAt: IndexPath)

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

func tableView(UITableView, titleForDeleteConfirmationButtonForRowAt: IndexPath)

Changes the default title of the delete-confirmation button.

func tableView(UITableView, shouldIndentWhileEditingRowAt: IndexPath)

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

Reordering Table Rows

func tableView(UITableView, targetIndexPathForMoveFromRowAt: IndexPath, toProposedIndexPath: IndexPath)

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

Tracking the Removal of Views

func tableView(UITableView, didEndDisplaying: UITableViewCell, forRowAt: IndexPath)

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

func tableView(UITableView, didEndDisplayingHeaderView: UIView, forSection: Int)

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

func tableView(UITableView, didEndDisplayingFooterView: UIView, forSection: Int)

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

Copying and Pasting Row Content

func tableView(UITableView, shouldShowMenuForRowAt: IndexPath)

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

func tableView(UITableView, canPerformAction: Selector, forRowAt: IndexPath, withSender: Any?)

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

func tableView(UITableView, performAction: Selector, forRowAt: IndexPath, withSender: Any?)

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

Managing Table View Highlighting

func tableView(UITableView, shouldHighlightRowAt: IndexPath)

Asks the delegate if the specified row should be highlighted.

func tableView(UITableView, didHighlightRowAt: IndexPath)

Tells the delegate that the specified row was highlighted.

func tableView(UITableView, didUnhighlightRowAt: IndexPath)

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

Managing Table View Focus

func tableView(UITableView, canFocusRowAt: IndexPath)

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

func tableView(UITableView, shouldUpdateFocusIn: UITableViewFocusUpdateContext)

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

func tableView(UITableView, didUpdateFocusIn: UITableViewFocusUpdateContext, with: UIFocusAnimationCoordinator)

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

func indexPathForPreferredFocusedView(in: UITableView)

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

Relationships