由于自适应每次刷新都会计算, 所以会造成闪烁,跳动, 将高度缓存下来就可以了
@property (nonatomic, strong) NSMutableDictionary *cellHightDic;// 记录cell高度
- 在
tableView:willDisplayCell:orRowAtIndexPath:
方法中记录cell的高度
[self.cellHightDic setObject:@(cell.frame.size.height) forKey:[NSString stringWithFormat:@"%ld_%ld",(long)indexPath.section, (long)indexPath.row]];
- 在
tableView:estimatedHeightForRowAtIndexPath:
方法中返回cell的高度
- (CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath {
CGFloat height = [[self.cellHightDic objectForKey:[NSString stringWithFormat:@"%ld_%ld",(long)indexPath.section, (long)indexPath.row]] floatValue];
if (height == 0) {
return 50;
}
return height;
}