Contents

cellForRow(at:)

Returns the table cell at the index path you specify.

Declaration

func cellForRow(at indexPath: IndexPath) -> UITableViewCell?

Parameters

  • indexPath:

    The index path locating the row in the table view.

Return Value

The cell object at the corresponding index path. In versions of iOS earlier than iOS 15, this method returns nil if the cell isn’t visible or if indexPath is out of range. In iOS 15 and later, this method returns a non-nil cell if the table view retains a prepared cell at the specified index path, even if the cell isn’t currently visible.

Discussion

In iOS 15 and later, the table view retains a prepared cell in the following situations:

  • Cells that the table view prefetches and retains in its cache of prepared cells, but that aren’t visible because the table view hasn’t displayed them yet.

  • Cells that the table view finishes displaying and continues to retain in its cache of prepared cells because they remain near the visible region and might scroll back into view.

  • The cell that contains the first responder.

  • The cell that has focus.

See Also

Getting cells and section-based views