Well, this sounds totally weird and I have been spending the last 3 hours trying to fix it. I have a table view with custom cell that contains two labels. The labels heights are variables and calculated using the method sizeWithFont:constrainedToSize:lineBreakMode
.
cell = [tableView dequeueReusableCellWithIdentifier:sCellIdentifier];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
cell.tariffPlanCellContentView.cellPrefixLabel.text = [NSString stringWithFormat:sPrefixStringWithColon, [self getPrefixStringAtIndexPath:indexPath]];
cell.tariffPlanCellContentView.cellPrefixLabel.textAlignment = UITextAlignmentLeft;
cell.tariffPlanCellContentView.cellPrefixLabel.frame = CGRectMake(cell.tariffPlanCellContentView.cellPrefixLabel.frame.origin.x,
cell.tariffPlanCellContentView.cellPrefixLabel.frame.origin.y,
kTableViewCellLabelWidth,
[self getSizeForPrefixStringAtIndexPath:indexPath].height);
cell.tariffPlanCellContentView.cellDetailsLabel.text = [self getDetailStringAtIndexPath:indexPath];
cell.tariffPlanCellContentView.cellDetailsLabel.frame = CGRectMake(cell.tariffPlanCellContentView.cellDetailsLabel.frame.origin.x,
cell.tariffPlanCellContentView.cellPrefixLabel.frame.origin.y + cell.tariffPlanCellContentView.cellPrefixLabel.frame.size.height + 3,
kTableViewCellLabelWidth,
[self getSizeForDetailsStringAtIndexPath:indexPath].height);
[cell.tariffPlanCellContentView.cellPrefixLabel sizeToFit];
[cell.tariffPlanCellContentView.cellDetailsLabel sizeToFit];
At the first load of the table view, all cells appear with one line only. Only when I scroll the table view (or programmatically reloading the table view "again"), the labels are fixed! I don't know why it's doing that? cellPrefixLabel
and cellDetailsLabel
are inside a custom cell loaded from nib. Both have numberOfLines = 0
Update
- I am not using Auto-Layout, I am still supporting iOS 5.
- The application is working fine on iOS 6 and the bug is only on iOS 7 beta 6! Is it due to the beta version? Does any one face anything like this?
- I removed sizeToFit and the same problem exists. In fact, sizeToFit doesn't help at all and it's not required on iOS 6.