About Uitableview--cell multiplexing issues

Source: Internet
Author: User

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

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.