1迷扇、不使用iOS自動(dòng)布局Autolayout百揭。
解決辦法:
self.tableView.estimatedRowHeight = 0;
self.tableView.estimatedSectionHeaderHeight = 0;
self.tableView.estimatedSectionFooterHeight = 0;
2、使用自動(dòng)布局蜓席,cell會自適應(yīng)高度器一。
在iOS10及以下,刷新cell厨内,cell會跳動(dòng)祈秕。
解決辦法:
// 定義一個(gè)可變數(shù)組記錄cell的歷史高度
@property (nonatomic, strong) NSMutableDictionary *cellHightDict;// 記錄cell高度的數(shù)組
// 之后,實(shí)現(xiàn)方法
- (NSMutableDictionary *)cellHightDict {
if (!_cellHightDict) {
_cellHightDict = [NSMutableDictionary new];
}
return _cellHightDict;
}
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
[self.cellHightDict setObject:@(cell.frame.size.height) forKey:[NSString stringWithFormat:@"%ld_%ld",(long)indexPath.section, (long)indexPath.row]];
}
- (CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath {
CGFloat height = [[self.cellHightDict objectForKey:[NSString stringWithFormat:@"%ld_%ld",(long)indexPath.section, (long)indexPath.row]] floatValue];
if (height == 0) {
return 100;
}
return height;
}