美文网首页
xib cell自适应高度

xib cell自适应高度

作者: LGirl | 来源:发表于2016-07-17 17:15 被阅读284次
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.

相关文章

网友评论

      本文标题:xib cell自适应高度

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