【干货】Xcode8最新UITableView动态计算高度

//声明tableview

@property(nonatomic,strong)UITableView * tableView;

//自定义的cell

@property(nonatomic,strong)TopicDetailsTableViewCell  * cell;


//把高度传过去(这个写在自定义cell的.h里,吧相对高度传过去)

@property(nonatomic,assign)CGFloat  maxCellY;

自定义cell的.m里

self.maxCellY = CGRectGetMaxY(labelAnswerContent.frame)+12;


//高度

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {

return _cell.maxCellY;

}

//cel定制方法

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

static NSString * string=@"strtopic";

_cell = [tableView dequeueReusableCellWithIdentifier:string];

if (_cell==nil) {

_cell=[[TopicDetailsTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:string];

}

AnswerModer * model = self.dataSouce[indexPath.row];

_cell.model = model;

return _cell;

}

如果喜欢请收藏,请关注我!

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容