cocoa touch - UITableViewCell - overlapping with previous cells contents -


i have wierd problem table

  1. i have 20 cells display
  2. each cell 84px in height
  3. when click no cell, have set background colour
  4. the first 4 cells ok, when scroll down , click on 5th cell, content of each cell starts overlap other content, content 1st 4 cells.

i belive cell reusability or drawing issue. not sure how solve it, have checked through code, not changing cell's content on touch.

here code , add pics cell overlapped content

- (cgfloat)tableview:(uitableview *)tableview heightforrowatindexpath:(nsindexpath *)indexpath {     return 104; } - (nsinteger)tableview:(uitableview *)tableview numberofrowsinsection:(nsinteger)section {       return [stores count]; }  -(uitableviewcell *)tableview:(uitableview *) tableview cellforrowatindexpath:(nsindexpath *)indexpath {     static nsstring *cellidentifier = @"cell";     cgrect label1frame = cgrectmake(5, 5, 250, 30);     cgrect label2frame = cgrectmake(6, 42, 220, 20);         cgrect label3frame = cgrectmake(6, 62, 220, 20);             cgrect label4frame = cgrectmake(240,56, 70, 12);                  uitableviewcell *cell = [tableview dequeuereusablecellwithidentifier:cellidentifier];      if(cell == nil) {         cell = [[[uitableviewcell alloc] initwithstyle:uitableviewcellstylevalue1 reuseidentifier:cellidentifier] autorelease];     }else{         // cell being recycled, remove old edit field (if contains 1 of our tagged edit fields)         uiview *viewtocheck = nil;         viewtocheck = [cell.contentview viewwithtag:1];         if (!viewtocheck) {             [viewtocheck removefromsuperview];             debuglog(@"view removed");         }            }     //cell.selectionstyle=uitableviewcellselectionstylenone;     [cell setselectedbackgroundview:bgview];         nsinteger row=indexpath.row;     uilabel *lbltemp;     [[cell contentview] clearscontextbeforedrawing];      //line 1      lbltemp=[[uilabel alloc] initwithframe: label1frame];     lbltemp.tag=1;     lbltemp.text=[[stores objectatindex:row] objectatindex:0] ;     lbltemp.numberoflines=2;     lbltemp.font = [uifont boldsystemfontofsize:13];     lbltemp.adjustsfontsizetofitwidth=yes;     lbltemp.minimumfontsize=12;     lbltemp.textcolor = [uicolor graycolor];     [cell.contentview addsubview:lbltemp];       [lbltemp release];     //line 2     lbltemp = [[uilabel alloc] initwithframe:label2frame];     lbltemp.tag = 2;     lbltemp.text=[[stores objectatindex:row]objectatindex:1];        lbltemp.font = [uifont systemfontofsize:12];     lbltemp.textcolor = [uicolor graycolor ];     lbltemp.textalignment=uitextalignmentleft;     lbltemp.adjustsfontsizetofitwidth=yes;     lbltemp.minimumfontsize=12;      [cell.contentview addsubview:lbltemp];       [lbltemp release];      //line 3         lbltemp = [[uilabel alloc] initwithframe:label3frame];     lbltemp.tag = 3;     lbltemp.text=[[stores objectatindex:row]objectatindex:2];     lbltemp.font = [uifont systemfontofsize:12];     lbltemp.textcolor = [uicolor graycolor ];     [cell.contentview addsubview:lbltemp];           [lbltemp release];     //phone button     uibutton *phonebutton=[[uibutton alloc] initwithframe:cgrectmake(240,16,30,30)];     [phonebutton setbackgroundimage:[uiimage imagenamed:@"phone.png"] forstate:uicontrolstatenormal];     [phonebutton settag:row];     [phonebutton addtarget:self action:@selector(dialnumber:) forcontrolevents:uicontroleventtouchupinside];     [cell.contentview addsubview:phonebutton];     //annotation button     uibutton *annotation=[[uibutton alloc] initwithframe:cgrectmake(274,16,30,30)];      [annotation settag:row];     [annotation setbackgroundimage:[uiimage imagenamed:@"tab.png"] forstate:uicontrolstatenormal];     [annotation addtarget:self action:@selector(openmap:) forcontrolevents:uicontroleventtouchupinside];         [cell.contentview addsubview:annotation];        [annotation release];     //distance label     //line 3         lbltemp = [[uilabel alloc] initwithframe:label4frame];     lbltemp.tag = 4;     lbltemp.text=[[stores objectatindex:row]objectatindex:5];        lbltemp.textalignment=uitextalignmentcenter;     lbltemp.font = [uifont systemfontofsize:13];     lbltemp.textcolor = [uicolor graycolor ];     [lbltemp setadjustsfontsizetofitwidth:yes];     [cell.contentview addsubview:lbltemp];           [phonebutton release];     [lbltemp release];       [cell setneedslayout];     [cell setneedsdisplay];     return cell; } -(void)tableview:(uitableview *)tableview didselectrowatindexpath:(nsindexpath *)indexpath {      uitableviewcell *cell=[tableview cellforrowatindexpath:indexpath ];        for(uilabel *lbl in cell.contentview.subviews){         if([lbl iskindofclass:[uilabel class]]){             lbl.textcolor=[uicolor whitecolor];          }     }     //uitableviewcell *cell1;            //nsstring *row=[nsstring stringwithformat:@"%d",indexpath.row];     svm = [[storesmapview alloc] initwithnibname:@"storesmapview" bundle:nil];     [svm initwithxml:stores:indexpath.row];     cgrect theframe = svm.view.frame;     theframe.origin = cgpointmake(self.view.frame.size.width, 0);     svm.view.frame = theframe;     theframe.origin = cgpointmake(0,0);     theframe.size=cgsizemake(320,355);     [uiview beginanimations:nil context:nil];      [uiview setanimationduration:0.3f];     svm.view.frame = theframe;     [uiview commitanimations];     [subview addsubview:svm.view];     backbutton.hidden=no;   } 

i figured out trial , error; if can one

in cellforrowatindexpath tried clear cells subview before drawing cell

//try remove content     for(uiview *view in cell.contentview.subviews){         if ([view iskindofclass:[uiview class]]) {             [view removefromsuperview];         }     } 

i happy if can point me easier way

thanks


Comments

Popular posts from this blog

java - SNMP4J General Variable Binding Error -

windows - Python Service Installation - "Could not find PythonClass entry" -

Determine if a XmlNode is empty or null in C#? -