两种方法
1.在控制器中创建一个cell专门用来计算cell的高度,用系统自带的计算cell高度的方法
1.在控制器中创建一个cell用来计算cell高度
@property (nonatomic, strong) UITableViewCell *prototypeCell;
self.prototypeCell = [self.tableView dequeueReusableCellWithIdentifier:@"HTAddressHeadViewCell"];
- - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
- C1 *cell = (C1 *)self.prototypeCell;
- cell.t.text = [self.tableData objectAtIndex:indexPath.row];
- CGSize size = [cell.contentView systemLayoutSizeFittingSize:UILayoutFittingCompressedSize];
- NSLog(@"h=%f", size.height + 1);
- return 1 + size.height;
- }
self.addressContentView.preferredMaxLayoutWidth = MainWidth - 130;
设置UIlabe的numberLines = 0
2.使用第三方框架"UITableView+FDTemplateLayoutCell.h"
return [tableView fd_heightForCellWithIdentifier:@"YYMyBillCell" cacheByIndexPath:indexPath configuration:^(YYMyBillCell *cell) {
cell.model = self.cellData[indexPath.row];
}];