What is the purpose of reuseIdentifier?

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier 

What is the purpose of reuse in this constructor.

+5
source share
4 answers

reuseIdentifier used to group similar rows in a UITableView .

A UITableView usually allocates enough UITableViewCell objects to display the content displayed in the table.

If reuseIdentifier not been set, the UITableView will force the selection of new UITableViewCell objects for each new element that scrolls in the view, which potentially leads to animation lags.

+12
source

doc says:

The reuse identifier is associated with the UITableViewCell object, which the view table delegate creates with the intention of reusing it as (for performance reasons) for several rows of the table view. This is assigned to the cell object in initWithFrame: reuseIdentifier: and cannot be changed after that. The UITableView object maintains a queue (or list) of reusable cells, each of which has its own reusable identifier and makes them available to the delegate in the dequeueReusableCellWithIdentifier: method.

reuseidentifier is an identifier from which you can get a cell from it.

+3
source

When a cell scrolls out of the scope of the screen, the object representing it is reused to scroll through the elements on the screen. The reuse identifier tells the system that the object can be reused for the cell entering the screen for which you are requesting the same identifier.

+1
source

Reuse identifiers are required by the UITableViewCell to support the deactivation of reusable cells by unambiguously identifying cell types. Usually you create a unique row reuse identifier for each type of cell used.

name it https://developer.apple.com/library/ios/documentation/UIKit/Reference/UITableViewCell_Class/#//apple_ref/occ/instp/UITableViewCell/reuseIdentifier

0
source

All Articles