iphone - Dynamic Height For UITableViewCell and The content inside -


i have particularly problem can't seem solve have looked @ code few hours , can't seem fix problem.

when add messages tableview messages overflows wrapper within uitableviewcell , wrapper gets cutoff cell.

how make sure wrapper big enough hold txt (lblmessage) , cell big enough hold wrapper.

thanks in advance !

-(cgfloat)tableview:(uitableview *)tableview heightforrowatindexpath:(nsindexpath *)indexpath {     cgfloat height = [self heightformessage:indexpath];      if(height < 50)     {         nslog(@"normal : %d , row : %d", 100,indexpath.row);         return 100;     }         else     {         nslog(@"custom : %f , row : %d", 70 + height,indexpath.row);         return 70 + height;     } }  -(cgfloat)heightformessage:(nsindexpath *)indexpath {     messageobject * model = [self.chats objectatindex:indexpath.row];      cgsize size = [model.message sizewithfont:[uifont fontwithname:@"helveticaneue-light" size:12] constrainedtosize:cgsizemake(290, 100000) linebreakmode:nslinebreakbywordwrapping];      return size.height; }  -(uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath {     static nsstring * newscellidentifer = @"newscellidentifier";     uitableviewcell * cell = [tableview dequeuereusablecellwithidentifier:newscellidentifer];      uilabel * lblcontact;     uilabel * lblmessage;     uilabel * lbldate;     uiview * wrapper;      if (cell == nil)     {          /* top menu login */          wrapper = [[uiview alloc] initwithframe:cgrectmake(10, 5, 300, 90)];         [wrapper setbackgroundcolor:[self.delegate.color colorwithalphacomponent:0.6f]];         [wrapper.layer setcornerradius:6.0f];         [wrapper.layer setshadowoffset:cgsizemake(0, 2)];         [wrapper.layer setshadowradius:2.0f];         [wrapper.layer setshadowopacity:0.5f];         [wrapper viewwithtag:19];         cell = [[uitableviewcell alloc] initwithstyle:uitableviewcellstylevalue1 reuseidentifier:newscellidentifer];          /* contact name */          lblcontact = [[uilabel alloc] initwithframe:cgrectmake(10, 0, 150, 30)];         [lblcontact setfont:[uifont fontwithname:@"helveticaneue-medium" size:13]];         [lblcontact settag:13];         [lblcontact settextcolor:[self.delegate colorfromhexstring:@"#fffbff"]];         [lblcontact setbackgroundcolor:[uicolor clearcolor]];          /* received message */          lblmessage = [[uilabel alloc] initwithframe:cgrectmake(10, 20, 280, 50)];         [lblmessage setnumberoflines:0];         [lblmessage setlinebreakmode:nslinebreakbywordwrapping];         [lblmessage setbackgroundcolor:[uicolor clearcolor]];         [lblmessage setfont:[uifont fontwithname:@"helveticaneue-light" size:12]];         [lblmessage settextcolor:[self.delegate colorfromhexstring:@"#fffbff"]];         [lblmessage settag:14];           /* date received */          lbldate = [[uilabel alloc] initwithframe:cgrectmake(10, 65, 65, 30)];         [lbldate settext:@"4 hours ago"];         [lbldate setfont:[uifont fontwithname:@"helveticaneue-light" size:11]];         [lbldate settextcolor:[self.delegate colorfromhexstring:@"#fffbff"]];         [lbldate settag:15];          /* subview logic */          [wrapper addsubview:lblcontact];         [wrapper addsubview:lblmessage];         [wrapper addsubview:lbldate];          [cell setselectionstyle:uitableviewcellselectionstylenone];         [cell.contentview addsubview:wrapper];     }     else     {         lblcontact = (uilabel *)[cell.contentview viewwithtag:13];         lblmessage = (uilabel *)[cell.contentview viewwithtag:14];         wrapper = [cell.contentview viewwithtag:19];     }      messageobject * model = [self.chats objectatindex:indexpath.row];      cgfloat height = [self heightformessage:indexpath];      [lblmessage setframe:cgrectmake(10, 25, 280, height)];     [lblmessage settext:model.message];      [lblcontact settext:model.clientmodel.firstname];      if(height < 50)     {         nslog(@"wrapper size : %d row %d ", 90, indexpath.row);         [wrapper setframe:cgrectmake(10, 5, 300, 90)];     }     else     {         nslog(@"wrapper size : %f row %d ", height + 60, indexpath.row);          [wrapper setframe:cgrectmake(10, 5, 300, height + 60)];         [lbldate setframe:cgrectmake(10, height + 20, 65, 30)];     }      [cell.contentview setbackgroundcolor:[uicolor greencolor]];     [cell setbackgroundcolor:[uicolor clearcolor]];      return cell;  } 

one of errors when creating wrapper view new cell line:

[wrapper viewwithtag:19]; 

should be:

[wrapper settag:19]; 

this causes wrapper nil when attempt resize on reused cell.


Comments

Popular posts from this blog

c# - How Configure Devart dotConnect for SQLite Code First? -

java - Copying object fields -

c++ - Clear the memory after returning a vector in a function -