- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
What is the purpose of the reuseIdentifier in above constructor.
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.
dequeueReusableCellWithIdentifier: Returns a reusable table-view cell object after locating it by its identifier.
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 .
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With