How does iOS-UITableViewCell object be reused?

Source: Internet
Author: User

 

 

The memory of iOS devices is limited. If you use UITableView to display thousands of data records,

If you need thousands of UITableViewCell objects,

That will consume the memory of the iOS device. To solve this problem, you need to reuse the UITableViewCell object.

 

 

 

When scrolling the list ,,

UITableView puts the UITableViewCell outside the window into it for reuse.

When UITableView requires dataSource to return UITableViewCell,

DataSource will,

If there is a UITableViewCell in the pool, dataSource will be used, and then UITableView will be re-displayed in the window to avoid this.

 

 

 

There is another very important issue: Sometimes you need to customize UITableViewCell (using a subclass to inherit UITableViewCell), and each row uses not necessarily the same UITableViewCell (such as QQ, text message chat layout ), therefore, a UITableView may have different types of UITableViewCell, and there are many different types of UITableViewCell in the object pool. Therefore, UITableView may get the UITableViewCell of the wrong type when reusing UITableViewCell!

Solution:

UITableViewCell has an NSString * attribute. When initializing UITableViewCell, You can input a specific string ID to set the reuseIdentifier (generally the class name of UITableViewCell is used ). When UITableView requires dataSource to return UITableViewCell, it first passes through. If yes, it will be reused. If no, it will be passed in with this string identifier.

 

 

 

Clear Saup

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.