iOS - Reload UITableView to Fix Cell Label Height
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
No comments:
Post a Comment