Instance Method

tableView(_:willSelectRowAt:)

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

Declaration

optional func tableView(_ tableView: UITableView, willSelectRowAt indexPath: IndexPath) -> IndexPath?

Parameters

tableView

A table-view object informing the delegate about the impending selection.

indexPath

An index path locating the row in tableView.

Return Value

An index-path object that confirms or alters the selected row. Return an NSIndexPath object other than indexPath if you want another cell to be selected. Return nil if you don'€™t want the row selected.

Discussion

This method is not called until users touch a row and then lift their finger; the row isn'€™t selected until then, although it is highlighted on touch-down. You can use UITableViewCell.SelectionStyle.none to disable the appearance of the cell highlight on touch-down. This method isn’t called when the table view is in editing mode (that is, the isEditing property of the table view is set to true) unless the table view allows selection during editing (that is, the allowsSelectionDuringEditing property of the table view is set to true).

See Also

Responding to Row Selections

func tableView(UITableView, didSelectRowAt: IndexPath)

Tells the delegate that the specified row is now selected.

func tableView(UITableView, willDeselectRowAt: IndexPath) -> 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.