0

Hi I am trying to dynamically change my row height based on textlabel and detailtextlabel.

Following is my code:

 NSString *title = [NSString stringWithFormat:@"%@%@%@",_note.committeeStaffName,@"  -  ",_note.dateCreated];
    cell.textLabel.text = title;
    cell.detailTextLabel.text = _note.note;

I am trying to adjust the height of row of a table based on the textLabel and detailTextLabel. The textLabel doesnt exceed one row. The detailTextLabel contains large texts of varying length. I have read several examples of the delegate method heightForRowAtIndexPath but none of them clearly states what has to be done in the method heightForRowAtIndexPath and what code should go in cellForRowAtIndexPath. Can anyone please clearly explain what code should go in the two method heightForRowAtIndexPath and cellForRowAtIndexPath to adjust the height of table row based on the content which includes textLabel and detailTextLabel.

Ashok Ambrose
  • 191
  • 3
  • 17
  • possible duplicate of [Change the UITableViewCell Height According to Amount of Text](http://stackoverflow.com/questions/9827126/change-the-uitableviewcell-height-according-to-amount-of-text) – CodaFi Mar 07 '13 at 00:34

1 Answers1

0

i am trying to give you solution idea of your problem. Hope it will help you.

 -(CGFloat)getLabelHeightForIndex:(NSString*)strTemplate{
CGSize maximumSize = CGSizeMake(tblView.frame.size.width-50, 20000);
NSString* result  = [strTemplate stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
strTemplate = result;
CGSize labelHeighSize = [strTemplate sizeWithFont: [UIFont fontWithName:@"HelveticaNeue-Light" size:14.0] constrainedToSize:maximumSize lineBreakMode:NSLineBreakByWordWrapping];
return labelHeighSize.height;

}
you should use above method to get height of any one Label i.e. textLabel or defaulttestLabel then manage another view on the center of other in tableView cell.

Nico
  • 1,788
  • 2
  • 23
  • 41