這是搜索到的原文
1、在Cell對應的xib文件中建立完整的約束。
2、使用
[cell.contentView systemLayoutSizeFittingSize:UILayoutFittingCompressedSize]
我的理解就是通過autolayout使用這個方法自動計算出cell的高度
方法對cell進行動態計算高度,然后在
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
返回cell的高度。
注意:
[cell.contentView systemLayoutSizeFittingSize:UILayoutFittingCompressedSize]
一定是cell.contentView,不能用cell。