xib cell自适应高度

self.tableView.estimatedRowHeight = 500;
self.tableView.rowHeight = UITableViewAutomaticDimension;
//并且返回cell高度的代理方法不写
//加载xib
ImageLabelCell *cell = [tableView dequeueReusableCellWithIdentifier:reuseID];
if (!cell) {
        cell = [[NSBundle mainBundle] loadNibNamed:@"ImageLabelCell" owner:nil options:nil].firstObject;
}
return cell;
在xib中给label约束:上下左右
这样,系统就自动计算label的高度了
如果出现的结果是cell的高度是系统默认的高度,那么说明给的约束不够
错误提示:
Warning once only: Detected a case where constraints ambiguously suggest a height of zero for a tableview cell’s content view. We’re considering the collapse unintentional and using standard height instead.
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容