专栏名称: Adrenine
iOS开发
目录
相关文章推荐
51好读  ›  专栏  ›  Adrenine

iOS笔记之UITableView自动计算cell高度

Adrenine  · 掘金  ·  · 2017-12-13 08:46

正文

方法一:使用系统自动计算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






请到「今天看啥」查看全文