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

What is the purpose of the reuseIdentifier in above constructor.

Riya Khanna
  • 246
  • 1
  • 3
  • 9
  • 1
    Possible duplicate of - http://stackoverflow.com/questions/2152180/iphone-what-are-reuseidentifiers-uitableviewcell – Vijay Masiwal May 27 '15 at 05:26
  • 4
    As per the Apple's doc - reuseIdentifier is a string used to identify the cell object if it is to be reused for drawing multiple rows of a table view. Pass nil if the cell object is not to be reused. You should use the same reuse identifier for all cells of the same form. – Vijay Masiwal May 27 '15 at 05:28

4 Answers4

25

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.

Tariq
  • 9,861
  • 12
  • 62
  • 103
  • yeah that's correct, A UITableView will normally allocate just enough UITableViewCell objects to display the content visible in the table. – Muhammad Waqas Jun 25 '20 at 22:56
6

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.

Rahul Tripathi
  • 168,305
  • 31
  • 280
  • 331
3

As a cell scrolls out of the viewable area of the screen, the object representing it gets reused for cells scrolling on to the screen. The reuse identifier tells the system that an object can be reused for a cell entering the screen for which you request the same identifier.

goofballLogic
  • 37,883
  • 8
  • 44
  • 62
0

Reuse identifiers are required by UITableViewCell in order to support the dequeueing of reusable cells by uniquely identifying cell types. Normally you create a unique string reuse identifier for each kind of cell you have use.

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

Sport
  • 8,570
  • 6
  • 46
  • 65