I am working on Tableview with dynamic cell height.
Due to my requirement, i have to show 40 types of different cell.Each cell is different.
For ex.
one cell having 2 labels,1 imageview another cell having only 2 imageview another cell having 5 labels,1 textview,2 buttons, 2 imageview
My problem is i cant able to define the height statically.ie. labels and textview in each cell is based on the text at run time.So according to the individual elements i need to adjust the height.So i have calculated the label and textview height based on below coding,
CGSize constrainedSize = CGSizeMake((IS_IPAD)?765:285 , 9999);
NSDictionary *dict=[array objectAtIndex:indexPath.row];
NSDictionary *attributesDictionary = [NSDictionary dictionaryWithObjectsAndKeys:
[UIFont fontWithName:@"Lucida Sans" size:(IS_IPAD)?18.0:12.0], NSFontAttributeName,
nil];
NSMutableAttributedString *string = [[NSMutableAttributedString alloc] initWithString:[dict valueForKey:@"response"]attributes:attributesDictionary];
CGRect requiredHeight = [string boundingRectWithSize:constrainedSize options:NSStringDrawingUsesLineFragmentOrigin context:nil];
return requiredHeight.size.height;
The above code works fine.But it's little bit difficult to calculate for 5-10 labels for a cell.Because i need to call 10 times for every cell.So it causes slow scrolling on tableview.Also after that i need to change every label/textview and imageview's y position frame.Is there any alternate to achieve this? Any help would be highly appreciated.
Thanks.