The nature of the problem: because the child view you are adding is not implemented in a custom cell, but is based on an instance created by the system's UITableViewCell class, each time the Cellforrow method creates a cell, each time a child view is created (button , label, etc.) added, will take up a lot of memory, so the use of multiplexing method, but the problem comes, when the cell out of the interface, from the queue to be reused, where the child view of the content is not eliminated, so you will be the original base and then create a sub-view added to cover the original view , the general view is transparent so that it becomes a layer of overlay.
Workaround:
The following is an example of a label added to the cell
Add a specific view instance to the cell's Contentview
Note: How do I identify a child view in the parent view?
Step1: When adding a child view, specify the tag value (greater than 0)
Step2: In order to find this child view, the specified view can be found by invoking the Viewwithtag method of the parent view
-(UITableViewCell *) TableView: (UITableView *) TableView Cellforrowatindexpath: (Nsindexpath *) Indexpath {
UITableViewCell *cell = [TableView dequeuereusablecellwithidentifier:@ "Cell1"];
if (Cell==nil) {
Cell=[[uitableviewcell alloc]initwithstyle:uitableviewcellstylesubtitle reuseidentifier:@ "Cell1"];
}
Forindexpath:indexpath the index to the system for registration, if you want to create it yourself, remove it.
[Email protected] "detail. ";
Cell.imageview.image=[uiimage imagenamed:@ "Icon1.png"];
[Email protected] "helo";
Try to find it in the cell by tag value.
UILabel *label= (uilabel*) [Cell.contentview viewwithtag:1];
if (Label==nil) {//If not found then new
Label=[[uilabel Alloc]init];
Set Tag value for label
label.tag=1;
Label.textcolor=[uicolor Redcolor];
Label.font=[uifont italicsystemfontofsize:40];
Label.frame=cgrectmake (0, 0, Cell.bounds.size.width, 42);
Label.textalignment=nstextalignmentcenter;
[Cell.contentview Addsubview:label];
}
Label.text=[nsstring stringwithformat:@ "%ld", Indexpath.row];
return cell;
}
Workarounds for adding sub-views in a cell reuse overlap problem