cell高度可变的tableView提升加载速度
//这里为可变cell高度计算方法
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
ManagerCell *cell = (ManagerCell *)[tableView dequeueReusableCellWithIdentifier:@"ManagerCell"];
cell.topicLb.text = [self.dataArr objectAtIndex:indexPath.row];
cell.topicLb.preferredMaxLayoutWidth = kScreenSize.width - 133 - 16;//固定lb宽度,来改变高度
[cell.topicLb sizeToFit];
BMLog(@"%s", __func__);
CGSize size = [cell.contentView systemLayoutSizeFittingSize:UILayoutFittingCompressedSize];
return size.height>32?(size.height +1 +1):32;//cell中text内容过少得时候,给cell一个固定不变的高度
}
//这里为提升速度的关键方法
//这段代码是为了让上一个方法运行次数减少(提升性能)
- (CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 150.f;
}
相关资料:https://www.shinobicontrols.com/blog/posts/2013/10/16/ios7-day-by-day-day-19-uitableview-row-height-estimation
计算cell中able高度
cell.topicLb.text = text;
cell.topicLb.preferredMaxLayoutWidth = kScreenSize.width - 133 - 16;
[cell.topicLb sizeToFit];
CGSize constraint = CGSizeMake(cell.topicLb.preferredMaxLayoutWidth, 20000.0f);
CGSize size = [text sizeWithFont:[UIFont systemFontOfSize:FONT_SIZE] constrainedToSize:constraint lineBreakMode:NSLineBreakByWordWrapping];