实现cell的动态高度

来源:互联网 发布:许嵩医生知乎 编辑:程序博客网 时间:2024/05/01 22:47

两种方法

1.在控制器中创建一个cell专门用来计算cell的高度,用系统自带的计算cell高度的方法


      1.在控制器中创建一个cell用来计算cell高度

  @property (nonatomic,strong) UITableViewCell *prototypeCell;

      

  self.prototypeCell  = [self.tableViewdequeueReusableCellWithIdentifier:@"HTAddressHeadViewCell"];



  1. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { 
  2.     C1 *cell = (C1 *)self.prototypeCell; 
  3.     cell.t.text = [self.tableData objectAtIndex:indexPath.row]; 
  4.     CGSize size = [cell.contentView systemLayoutSizeFittingSize:UILayoutFittingCompressedSize]; 
  5.     NSLog(@"h=%f", size.height + 1); 
  6.     return 1  + size.height; 

 self.addressContentView.preferredMaxLayoutWidth = MainWidth -130;

设置UIlabe的numberLines = 0


2.使用第三方框架"UITableView+FDTemplateLayoutCell.h"

 return [tableViewfd_heightForCellWithIdentifier:@"YYMyBillCell"cacheByIndexPath:indexPathconfiguration:^(YYMyBillCell *cell) {

        cell.model =self.cellData[indexPath.row];

 }];

使用这个矿建xib中的控件不设高度

0 0
原创粉丝点击