I have a table with different entries, each with different length. The height of each row should fit, so it can show the whole string.
I use the following code:
//... cellForRowAtIndexPath
if (row == 0) {
cell = [tableView dequeueReusableCellWithIdentifier:@"affCell"];
//if (!cell) {
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:@"affCell"]autorelease];
cell.accessoryType = UITableViewCellAccessoryNone;
cell.selectionStyle = UITableViewCellSelectionStyleNone;
cell.autoresizingMask = UIViewAutoresizingFlexibleHeight;
affL = [[UILabel alloc] initWithFrame:CGRectZero];
affL.textAlignment = UITextAlignmentLeft;
affL.autoresizingMask = UIViewAutoresizingFlexibleHeight;
[cell.contentView addSubview:affL];
//}
//declaration label
affL.text = [fDictionary objectForKey:@"aff"];
affL.numberOfLines = 0;
[affL sizeToFit];
affL.frame = CGRectMake(15.0, 10.0, 220.0, affL.frame.size.height);
CGFloat affLH = affL.frame.size.height;
[tableView setRowHeight:affLH+30];
I also use
//... heightForRowAtIndexPath
return affL.frame.size.height;
How can I fix this problem?