正文
方法一:使用系统自动计算cell高度
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewCell *cell =
[self tableView:tableView cellForRowAtIndexPath:indexPath];
return [cell.contentView systemLayoutSizeFittingSize:
UILayoutFittingCompressedSize].height;
}
方法二:使用第三方库
下载地址:
UITableView-FDTemplateLayoutCell
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
NSString *cellReuseId = [self getReuseIdWithIndexPath:indexPath]; //获取cell id
CGFloat height = [tableView fd_heightForCellWithIdentifier:cellReuseId cacheByIndexPath:indexPath configuration:^(id cell) {
[self configureCell:cell indexPath:indexPath]; //对cell进行赋值
}];
return