iOS cell高度缓存

参考博客

为什么要缓存高度?

正常情况下,heigtForRowAtIndexPath: 方法会被调用很多次,在 UITableview 滚动的过程中也会不断的调用,这时如果我们只计算一次 Cell的高度,之后每次调用时都返回缓存的高度,就能让 UITableview 的滑动更加流畅,尤其是对高度计算特别耗时的复杂的 Cell 来说.

使用UITableView+FDTemplateLayoutCell.h

一句搞定
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
return [tableView fd_heightForCellWithIdentifier:cellidentifer cacheByIndexPath:indexPath configuration:^(TestCell *cell) {
[cell setTestModel:self.dataArray[indexPath.row]];
}];
}
并且已经对Cell高度进行了缓存,至于缓存的原理还在研究中。。

在cell中可以用Masonry进行布局
[self.iconView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(10);
make.top.mas_equalTo(10);
make.width.mas_equalTo(50);
make.height.mas_equalTo(50);
}];
[self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(self.iconView.mas_right).with.offset(10);
make.top.mas_equalTo(self.iconView.mas_top).with.offset(10);
make.right.mas_equalTo(-10);
}];

[self.timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
    make.left.mas_equalTo(self.nameLabel.mas_left);
    make.top.mas_equalTo(self.nameLabel.mas_bottom).with.offset(10);
    make.right.mas_equalTo(-10);
}];

[self.contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
    make.left.mas_equalTo(self.iconView.mas_left);
    make.top.mas_equalTo(self.iconView.mas_bottom).with.offset(10);
    make.right.mas_equalTo(-10);
    make.bottom.mas_equalTo(-10);
}];

但是出现的问题是如果有图片用第三方布局会出现问题,暂时还没有解决。

页面如下:


Simulator Screen Shot - iPhone 8 Plus - 2018-05-21 at 16.33.48.png

demo下载地址,大神有什么建议可以评论下。

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

推荐阅读更多精彩内容