views:

29

answers:

2

I need to present some information in a table view where some information is pretty flat, and other is pretty big. i.e. one information is just a line of text really, while the other is three lines of text.

From what I know, UITableView asks for the hight of all cells. So is there any way to have cells with distinct heights?

+5  A: 

Yes, see:

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath

Example implementation:

NSString *string...;
CGFloat CellWidth...;
CGSize size = [string sizeWithFont:[UIFont systemFontOfSize:14.0] 
               constrainedToSize:CGSizeMake(textWidth, MAXFLOAT) 
                   lineBreakMode:UILineBreakModeWordWrap];
CGFloat height = size.height;
if (height + 13.0) < 44.0) {
    return 44.0;
}
return height + 13.0;
Paul Lynch
+1  A: 

I agree with paull, but you could also subclass if you wanted something extra than just resizing the height. Just think about what else you may need. Good luck, cocoa can be a real pain sometimes.

Shadow