Skip to content

Commit de57a1a

Browse files
Tyler FoxTyler Fox
authored andcommitted
Set the preferredMaxLayoutWidth when returning a cell
1 parent 6512f1f commit de57a1a

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

TableViewCellWithAutoLayout/TableViewController/RJTableViewController.m

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,13 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
147147

148148
// Make sure the constraints have been added to this cell, since it may have just been created from scratch
149149
[cell setNeedsUpdateConstraints];
150+
[cell updateConstraintsIfNeeded];
151+
152+
// Since we have multi-line labels, do an initial layout pass and then set the preferredMaxLayoutWidth
153+
// based on their width so they will wrap text and take on the correct height
154+
[cell.contentView setNeedsLayout];
155+
[cell.contentView layoutIfNeeded];
156+
cell.bodyLabel.preferredMaxLayoutWidth = CGRectGetWidth(cell.bodyLabel.frame);
150157

151158
return cell;
152159
}

0 commit comments

Comments
 (0)