ios-on the overlap of cells

Source: Internet
Author: User

Remember that there was a problem a long time ago, about the cell overlap problem, now review and summarize.

TableView cell display in iOS will consume memory, if you want to display countless cells, it is not possible to store each cell, in order to solve this problem, the cell uses a reuse mechanism, the number of cells per display in TableView is limited, The number of cells is able to display the maximum number of cells, when more than the maximum number of cells can be displayed, will be reused before the cell created, there is a cell overlap problem, such as the creation of the first Cell,cell inside a label, when reused to this cell, If the label is not realistic, the cell overlap may occur.

Workaround:

Each of the 1.cell identifiers is different. Although the problem is solved, the memory consumption is huge.

NSString *cellidentifier = [NSString stringwithformat:@ "cell%d%d", [Indexpath section], [Indexpath row]];// Uniquely identify the cell with Indexpath.

2. Delete all the sub-views below the cell.

if (cell = = nil) {

cell = [[UITableViewCell alloc] Initwithstyle:uitableviewcellstyledefault reuseidentifier:cellidentifier];

}

Else

{

Delete all child views of a cell

while ([Cell.contentView.subviews lastobject]! = nil)

{

[(uiview*) [Cell.contentView.subviews Lastobject] removefromsuperview];

}

}

//... Other code

}

ios-on the overlap of cells

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.