我有一个摘要单元格,它使用systemLayoutSizeFittingSize计算它的高度。它的工作基本上和预期的一样。高度由三个多行标签(标题、作者、体裁)和一个分级图像视图决定,外部元素被附加到contentView。
当标题标签溢出到下一行时,它会适当地调整大小。然而,当作者标签溢出时,它似乎没有适当地增加大小。
标签和图像视图上的所有压缩电阻都在1000时达到最大值。如果右方的内容小于缩略图,则缩略图的底部有一个较低的优先级约束。(@750,来自超级视图底部的底部== 8)。分级图像视图也对superview底部有一个约束(@1000,来自superview底部的底部>= 8)。

发布于 2014-05-01 01:10:16
有意思的。因此,在更新内容和计算高度之前,我总是重置参考单元格帧的高度,从而解决了这个问题。不完全确定为什么需要这一步。我对contentView上的自动调整大小约束有几个猜测:
- (CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
switch (indexPath.section) {
case TableSectionSummary: {
TCAnswerDetailAppSummaryCell *cell = self.summaryCell;
CGRect oldFrame = self.summaryCell.frame;
cell.frame = CGRectMake(oldFrame.origin.x, oldFrame.origin.y, mTCTableViewFrameWidth, 400);
[cell configureWithThirdPartyObject:self.app];
[cell updateConstraintsIfNeeded];
[cell layoutIfNeeded];
CGFloat height = [cell.contentView systemLayoutSizeFittingSize:UILayoutFittingCompressedSize].height + 1;
return height;
}
case TableSectionDetails:
return [TCAnswerDetailBasicCell heightForCellWithTableWidth:mTCTableViewFrameWidth withLabelString:self.app.appDescription withDisclosureArrow:NO];
}
return 0;
}https://stackoverflow.com/questions/23399778
复制相似问题