ios tableview 使用自动布局后刷新时页面跳动 闪烁问
2019-12-13 本文已影响0人
FM_0138
- 设置tableview为自适应高度
self.tableView.estimatedRowHeight = 0;
self.tableView.estimatedSectionHeaderHeight = 0;
self.tableView.estimatedSectionFooterHeight = 0;
- 由于自适应每次刷新都会计算, 所以会造成闪烁,跳动, 将高度缓存下来就可以了
- 定义一个字典, 存放高度
@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; }