Recently made a nine-Gongge with TableView. Two cell multiplexing problems were encountered during the process.
Question one:
When you add a Addtarget Click event to a button in a cell, the cell that precedes it overlaps the event of the cell that appears behind it. The code is as follows:
C code
StaticNSString *cellwithidentifier =@"Discoverhometableviewcell"; Discoverhometableviewcell*CELL1 =[TableView dequeuereusablecellwithidentifier:cellwithidentifier Forindexpath:indexpath]; Cell1.Delegate=Self ; [Cell1.btnmore addtarget:self Action: @selector (Btnmoredisplay) forcontrolevents:uicontroleventtouchupinside]; Cell1.labTitle.text=@"Popular"; Cell1.listexhibit=_homevo.listexhibit; Cell1.dtype=d_type_1; Cell1.navigationcontroller=Self.navigationcontroller; [Cell1.tableview Reloaddata]; returnCell1;
After debugging, it is true that the previous cell event was reused. In this case, the protocol agent solves this problem by using the protocol to handle the Click event.
C code
#pragma Mark Discoverhometableviewcelldelegate -(void) Actionwithtap: (NSString *) type Withdata: (ID) data{ if ([type isequaltostring:d_type_1]) { [self Btnmoredisplay]; } }
Question two:
In UITableViewCell, the control is added in handwritten code, and when the cell is reused, overlapping controls and the contents of the control appear. Because each cell is re-added, the front cell is overwritten on the back of the cell. The controls added to the cell are then forced to empty, and the cell is reused, except that the contents of the previous cell are emptied before the new cell is loaded. The code is as follows:
C code
-(UITableViewCell *) TableView: (UITableView *) TableView Cellforrowatindexpath: (Nsindexpath *) indexpath{StaticNSString *cellidentifer =@"Discoverhomeinnertableviewcell"; Discoverhomeinnertableviewcell*cell =[TableView Dequeuereusablecellwithidentifier:cellidentifer Forindexpath:indexpath]; //TODO solves cell multiplexing overlap issues for(UIView *subviewinch[Cell.contentview Subviews]) {[Subview Removefromsuperview]; } UIButton*button =[UIButton Buttonwithtype:uibuttontypecustom]; //button Related Settings[Cell.contentview Addsubview:button]; UILabel*lab =[[UILabel alloc] init]; //Lab-Related Settings[Cell.contentview Addsubview:lab];
About Uitableview--cell multiplexing issues