动态获取cell高度

- (CGFloat)getCellHeight:(UITableViewCell*)cell
{
    [cell layoutIfNeeded];
    [cell updateConstraintsIfNeeded];
    
    CGFloat height = [cell.contentView systemLayoutSizeFittingSize:UILayoutFittingCompressedSize].height;
    return height;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    //只创建一个cell用作测量高度
    static MyOrderCell *cell = nil;
    
    if (!cell){
        cell = [tableView dequeueReusableCellWithIdentifier:@"MyOrderCellId"];
    }
    
    OrderItemModel * item = [self.dataHelper getDataListBySection:indexPath.section][0];
    
    [cell setCellInfo:item];
    
    float heigh = [self getCellHeight:cell];
    
    return heigh;
}
原文地址:https://www.cnblogs.com/h-tao/p/5157049.html