iphone - Custom uitableview cell issue -


i have custom uitableviewcell such:

@implementation cellwiththreesubtitles  @synthesize title, subtitle1, subtitle2, subtitle3;  - (id)initwithstyle:(uitableviewcellstyle)style reuseidentifier:(nsstring *)reuseidentifier {     if (self = [super initwithstyle:style reuseidentifier:reuseidentifier]) {         self.textlabel.backgroundcolor = self.backgroundcolor;         self.textlabel.opaque = no;         self.textlabel.textcolor = [uicolor blackcolor];         self.textlabel.highlightedtextcolor = [uicolor whitecolor];         self.textlabel.font = [uifont boldsystemfontofsize:22.0];     }     return self; }  - (void)layoutsubviews {     [super layoutsubviews];     cgrect contentrect = self.contentview.bounds;      cgrect frame = cgrectmake(35.0, 0, contentrect.size.width, 50.0);     self.textlabel.frame = frame;      uilabel *sublabel1 = [[uilabel alloc] init];     frame = cgrectmake(35.0, 34.0, contentrect.size.width, 25.0);     sublabel1.font = [uifont systemfontofsize:18.0];     sublabel1.backgroundcolor = [uicolor clearcolor];     sublabel1.text = subtitle1;     sublabel1.opaque = no;     sublabel1.frame = frame;     [self.contentview addsubview:sublabel1];      uilabel *sublabel2 = [[uilabel alloc] init];     frame = cgrectmake(35.0, 54.0, contentrect.size.width, 25.0);     sublabel2.font = [uifont boldsystemfontofsize:18.0];     sublabel2.backgroundcolor = [uicolor clearcolor];     sublabel2.text = subtitle2;     sublabel2.opaque = no;     sublabel2.frame = frame;     [self.contentview addsubview:sublabel2];      uilabel *sublabel3 = [[uilabel alloc] init];     frame = cgrectmake(contentrect.size.width-100.0, 54.0, contentrect.size.width, 25.0);     sublabel3.font = [uifont systemfontofsize:18.0];     sublabel3.backgroundcolor = [uicolor clearcolor];     sublabel3.text = subtitle3;     sublabel3.opaque = no;     sublabel3.frame = frame;     [self.contentview addsubview:sublabel3];  }  - (void)setselected:(bool)selected animated:(bool)animated {      [super setselected:selected animated:animated];      // configure view selected state }   - (void)dealloc {     [super dealloc];     [subtitle4 release];     [subtitle3 release];     [subtitle2 release];     [subtitle1 release];     [title release];  } 

when implement in uitableview this:

- (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath {     int section = [indexpath indexatposition:0];         static nsstring *kcustomcellid = @"appointmentcellid";      cellwiththreesubtitles *cell = (cellwiththreesubtitles *)[tableview dequeuereusablecellwithidentifier:kcustomcellid];     if (cell == nil) {         cell = (cellwiththreesubtitles *)[[[cellwiththreesubtitles alloc] initwithstyle:uitableviewcellstyledefault reuseidentifier:kcustomcellid] autorelease];     }      switch (section) {         case 0:              if ([winearray count]==0) {                 cell.textlabel.text = @"no wine favorites selected yet";             }else{                 cell.subtitle1 = [[winearray objectatindex:indexpath.row] objectforkey:@"varietal"];                 cell.subtitle2 = [nsstring stringwithformat:@"bin no. %@", [[winearray objectatindex:indexpath.row] objectforkey:@"bin"]];                 cell.subtitle3 = [nsstring stringwithformat:@"$%@", [[winearray objectatindex:indexpath.row] objectforkey:@"price"]];                 cell.textlabel.text = [nsstring stringwithformat:@"%@ (%@)", [[winearray objectatindex:indexpath.row] objectforkey:@"name"], [[winearray objectatindex:indexpath.row] objectforkey:@"availability"]];             }             cell.selectionstyle = uitableviewcellselectionstylenone;                         cell.userinteractionenabled = no;              break;                   case 1:              if ([dinnerarray count]==0)                 cell.textlabel.text = @"no dinner favorites selected yet";             else                  cell.textlabel.text = [nsstring stringwithformat:@"%@", [[dinnerarray objectatindex:indexpath.row] objectforkey:@"name"]];                    break;     }        return cell; } 

the contents of cell duplicates on top of every time orientation of device changes. redrawing cell every time device rotates? , if so, how can keep doing so?

you should creating subviews , adding them cell's subviews array in -initwithstyle:reuseidentifier: method. need create subviews once. -layoutsubviews method invoked repeatedly framework whenever device orientation changes, allow resize and/or move subviews (plus make other minor adjustments) compensate differences between orientations.


Comments

Popular posts from this blog

ASP.NET/SQL find the element ID and update database -

jquery - appear modal windows bottom -

c++ - Compiling static TagLib 1.6.3 libraries for Windows -