问题
I'm trying to use the new method of creating flexible height cells in iOS 8 by instantiating with these two lines of code:
tableView.estimatedRowHeight = 100.0
tableView.rowHeight = UITableViewAutomatic Dimension
I've set autolayout constraints that all satisfied. When I put in the message "This is a test message." the table cell adjusts for the correct height for that short message.
However when I try to add text that causes the text to wrap (in this case I just copied and pasted "This is a test message." 9 times over), the cell height adjusts for the new content but the text doesn't wrap. I've set the number of lines on the label to 0. Thoughts?
回答1:
Created a new table cell and tweaked one of my labels compression resistance priorities to be 751 instead of 750.
回答2:
I also ran into this issue but only on the 5/5s, while the 6/6+ worked.
The solution I found was to make the cell in the nib wider than 320 points, and force it to re-calculate its preferredMaxLayoutWidth:
- (void)layoutSubviews
{
[super layoutSubviews];
self.questionLabel.preferredMaxLayoutWidth = self.questionLabel.frame.size.width;
[super layoutSubviews];
}
When iOS has to resize the cell to fit in the Table View it will recalculate the wrapping of the cell's content.
来源:https://stackoverflow.com/questions/27197594/using-ios-8-flexible-table-cells-cell-height-changes-but-text-doesnt-wrap