UITableViewAutomaticDimension无效

对于cell中的子控件使用autolayout布局的tableview,iOS 8+可以使用以下代码高度自适应

self.tableView.rowHeight = UITableViewAutomaticDimension;
self.tableView.estimatedRowHeight = 100;

estimatedRowHeight此处值可以填写不为0的任意值,不能不设置。
如果iOS 8使用了以上自适应方法,但单元格并没有自适应,需要在cellForRowAtIndexPath方法中,添加如下代码

[cell setNeedsUpdateConstraints];
[cell updateConstraintsIfNeeded];

以上方法添加在return cell 之前

你可能感兴趣的:(UITableViewAutomaticDimension无效)