selectRow(at:animated:scrollPosition:)
Selects a row in the table view that an index path identifies, optionally scrolling the row to a location in the table view.
Declaration
func selectRow(at indexPath: IndexPath?, animated: Bool, scrollPosition: UITableView.ScrollPosition)Parameters
- indexPath:
An index path identifying a row in the table view.
- animated:
True if you want to animate the selection and any change in position; False if the change should be immediate.
- scrollPosition:
A constant that identifies a relative position in the table view (top, middle, bottom) for the row when scrolling concludes. See Scrollposition for descriptions of valid constants.
Mentioned in
Discussion
Calling this method doesn’t cause the delegate to receive a tableView(_:willSelectRowAt:) or tableView(_:didSelectRowAt:) message, nor does it send selectionDidChangeNotification notifications to observers.
Special considerations
Passing UITableView.ScrollPosition.none results in no scrolling, rather than the minimum scrolling described for that constant. To scroll to the newly selected row with minimum scrolling, select the row using this method with UITableView.ScrollPosition.none, then call scrollToRow(at:at:animated:) with UITableView.ScrollPosition.none.
NSIndexPath *rowToSelect; // assume this exists and is set properly
UITableView *myTableView; // assume this exists
[myTableView selectRowAtIndexPath:rowToSelect animated:YES scrollPosition:UITableViewScrollPositionNone];
[myTableView scrollToRowAtIndexPath:rowToSelect atScrollPosition:UITableViewScrollPositionNone animated:YES];