Instance Method

dequeueReusableCellWithIdentifier:forIndexPath:

Returns a reusable table-view cell object for the specified reuse identifier and adds it to the table.

Declaration

- (__kindof UITableViewCell *)dequeueReusableCellWithIdentifier:(NSString *)identifier forIndexPath:(NSIndexPath *)indexPath;

Parameters

identifier

A string identifying the cell object to be reused. This parameter must not be nil.

indexPath

The index path specifying the location of the cell. Always specify the index path provided to you by your data source object. This method uses the index path to perform additional configuration based on the cell’s position in the table view.

Return Value

A UITableViewCell object with the associated reuse identifier. This method always returns a valid cell.

Discussion

Call this method only from the tableView:cellForRowAtIndexPath: method of your table view data source object. This method returns an existing cell of the specified type, if one is available, or it creates and returns a new cell using the class or storyboard you provided earlier. Do not call this method outside of your data source's tableView:cellForRowAtIndexPath: method. If you need to create cells at other times, call dequeueReusableCellWithIdentifier: instead.

When creating new cells from your storyboard or nib file, this method loads the cell object and initializes it using its initWithCoder: method. When creating cells from a registered class, this method creates the cell and initializes it by calling its initWithStyle:reuseIdentifier: method. For nib-based cells, this method loads the cell object from the provided nib file. If an existing cell was available for reuse, this method calls the cell’s prepareForReuse method instead.

See Also

Recycling Table View Cells

- registerNib:forCellReuseIdentifier:

Registers a nib object containing a cell with the table view under a specified identifier.

- registerClass:forCellReuseIdentifier:

Registers a class for use in creating new table cells.

- dequeueReusableCellWithIdentifier:

Returns a reusable table-view cell object located by its identifier.