Solution to content error caused by Cell reuse mechanism in UITableView

Source: Internet
Author: User

UITableView saves memory by reusing cells. by specifying a reuseIdentifier for each cell, you can specify the cell type and when the cell gets out of the screen, allows restoring cells for reuse. different IDs are used for different types of cells, and an identifier is enough for a simple table.

Assume that a table view contains 10 cells, but up to four cells can be displayed on the screen. In fact, the iPhone only allocates four cells of memory for the table view, but does not allocate 10 cells, when you scroll a cell, the cells displayed on the screen reuse the four memories. In fact, the number of allocated cells is the maximum number of cells displayed on the screen. When a new Cell enters the screen, the memory occupied by the Cell that has been rolled out of the screen is randomly called, which is the reuse of the Cell.

For a variable custom cell, this reuse mechanism will cause content errors. In order to solve this error, after repeated google, we finally found a suitable method. The original

UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier: defineString]; changed:


UITableViewCell * cell = [tableView cellForRowAtIndexPath: indexPath];

In this way, the problems caused by cell reuse can be solved.
 

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.