这里只讲,如何使用系统的方法计算Cell高度:
要点1:XIB的布局的方式是重中之重,要遵循自上而下,比如类似朋友圈的布局;
中间“detailLabel”需要自动计算高度,以detaiLabel为分割,上方控件从上而下,下方控件从下而上,detail.top =“上部控件”.bottom,detail.bottom =“下部控件”.top,不用设置DetailLabel的高度;
要点2:设置系统的预估值属性
tablel.rowHeight = UITableViewAutomaticDimension ;
table.estimatedRowHeight = 300 ;
要点3:如果遇到 “unable to simultaneously satisfy constaints” 错误,
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x7fbb85e6f500 V:[UIImageView:0x7fbb85e79b80(200)]>
选中要修改的约束,将其值调低(999)即可。