Cell reuse methods and cell reuse methods

Source: Internet
Author: User

Cell reuse methods and cell reuse methods

1. Use xib for Reuse

// Recommended reuse method after ios6

// Use self dynamically to obtain the current class name as a unique identifier

NSString * identifier = NSStringFromClass ([self class]);

UINib * nib = [UINib nibWithNibName: identifier bundle: nil];

// Register

[TableView registerNib: nib forCellReuseIdentifier: identifier];

// First go to the cache pool. If there is no reusable cell in the cache pool, create a cell object based on the previously registered nib and return it to you.

GPSubjectCell * cell = [tableView dequeueReusableCellWithIdentifier: identifier];

Return cell;

 

2. Pure code

 

 

// Ensure the uniqueness of the label. Using the class name is a good choice.

NSString * identifier = @ "GPSubjectCell ";

// 1. Check whether the cache pool can be reused.

GPSubjectCell * cell = [tableView dequeueReusableCellWithIdentifier: identifier];

// 2. If no reuse is available, create one by yourself.

If (cell = nil)

{

Cell = [[self alloc] initWithStyle: UITableViewCellStyleDefault reuseIdentifier: identifier];

}

Return cell;

3.

// Use the registration mechanism to reuse the cell class with pure code

NSString * className = NSStringFromClass ([self class]);

[TableView registerClass: [self class] forCellReuseIdentifier: className];

Return [tableView dequeueReusableCellWithIdentifier: className];

 

4. When using storyboard, (but a Identifier must be provided for the cell)

Return [collectionView dequeueReusableCellWithReuseIdentifier: @ "bookCell" forIndexPath: indexPath];

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.