美文网首页错误收集
UITableViewAutomaticDimension无效

UITableViewAutomaticDimension无效

作者: Mystical | 来源:发表于2017-11-24 17:18 被阅读218次

对于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无效

    本文链接:https://www.haomeiwen.com/subject/agefbxtx.html