systemLayoutSizeFittingSize:在不同的iOS版本上返回不同的结果

时间:2015-07-06 08:36:29

标签: ios objective-c uitableview nsattributedstring

我有一个UITableView的原型单元格,我使用以下代码计算其高度:

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [self tableView:tableView cellForRowAtIndexPath:indexPath];
    [cell layoutIfNeeded];
    CGSize size = [cell.contentView systemLayoutSizeFittingSize:UILayoutFittingCompressedSize];
    return size.height + 1;
}

我在cellForRowAtIndexPath内出列的单元格中只有一个UILabel,并且我将NSAttributedString设置为其文本。

问题是,当我在iOS 7.1模拟器上运行时,一切都很完美。但是,当我在iOS 8.4模拟器上运行它时,会返回一个更大的高度,因此单元格底部有足够的空间。可能是什么导致了这个?任何评论或建议将不胜感激。

1 个答案:

答案 0 :(得分:0)

您可以参考以下链接

iOS 8.3 breaks automatic cell height

此链接可能会对您有所帮助。

我搜索了这个,但没有尝试过。