自定义约束下的cell的高度

来源:互联网 发布:php防止ajax重复提交 编辑:程序博客网 时间:2024/06/01 09:33

xib中包含了UILabel,由于UILabel的高度是不确定的,所以cell的高度也是不确定的

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{}

ios7出现了估计高度 取代了原来需要一下算出所有的高度,显示多少计算多少,这样更加有效率,节省内存

-(CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(nonnull NSIndexPath *)indexPath{    UITableViewCell *cell = [self tableView:tableView cellForRowAtIndexPath:indexPath];    CGSize size = [cell.contentView systemLayoutSizeFittingSize:UILayoutFittingCompressedSize];    return size.height + 1.0f;}

当然这个是不能取代原来设置cell高度的方法,当没有约束的时候,还是需要设置固定高度

0 0
原创粉丝点击