Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the purpose of the reuseIdentifier?

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

What is the purpose of the reuseIdentifier in above constructor.

like image 286
Riya Khanna Avatar asked May 27 '15 05:05

Riya Khanna


People also ask

What is the purpose of the reuseIdentifier Swift?

The reuse identifier is associated with a UITableViewCell object that the table-view's delegate creates with the intent to reuse it as the basis (for performance reasons) for multiple rows of a table view. It is assigned to the cell object in init(frame:reuseIdentifier:) and cannot be changed thereafter.

What is the use of dequeueReusableCellWithIdentifier in IOS?

dequeueReusableCellWithIdentifier: Returns a reusable table-view cell object after locating it by its identifier.

How does Dequereusablecell func work internally?

This method dequeues an existing cell if one is available or creates a new one using the class or nib file you previously registered. If no cell is available for reuse and you didn't register a class or nib file, this method returns nil .

How can we use a reusable cell in UITableView?

All we need to do to is use the prepareForReuse() function. This function is called before cell reuse, letting you cancel current requests and perform a 'reset'. Below I show you what a custom table view cell might look like. Add the code below to the UITableViewCell and you should be good to go.


2 Answers

The doc says:

The reuse identifier is associated with a UITableViewCell object that the table-view’s delegate creates with the intent to reuse it as the basis (for performance reasons) for multiple rows of a table view. It is assigned to the cell object in initWithFrame:reuseIdentifier: and cannot be changed thereafter. A UITableView object maintains a queue (or list) of the currently reusable cells, each with its own reuse identifier, and makes them available to the delegate in the dequeueReusableCellWithIdentifier: method.

reuseidentifier is an id from which you can get cell from it.

like image 190
Rahul Tripathi Avatar answered Sep 23 '22 10:09

Rahul Tripathi


The reuseIdentifier is used to group together similar rows in an UITableView.

A UITableView will normally allocate just enough UITableViewCell objects to display the content visible in the table.

If reuseIdentifier has not been set, the UITableView will be forced to allocate new UITableViewCell objects for each new item that scrolls into view, potentially leading to laggy animations.

like image 42
Tariq Avatar answered Sep 24 '22 10:09

Tariq