@property(nonatomic,strong)NSMutableDictionary*heightAtIndexPath;//缓存高度所用字典
#pragma mark - UITableViewDelegate-(CGFloat)tableView:(UITableView*)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath*)indexPath{
NSNumber*height = [self.heightAtIndexPath objectForKey:indexPath];if(height) {returnheight.floatValue; }
else
{return100; }
}
- (void)tableView:(UITableView*)tableView willDisplayCell:(UITableViewCell*)cell forRowAtIndexPath:(NSIndexPath*)indexPath{
NSNumber*height = @(cell.frame.size.height); [self.heightAtIndexPath setObject:height forKey:indexPath];
}
本文介绍了一种在UITableView中缓存单元格高度的方法,通过使用NSMutableDictionary来存储不同indexPath对应的单元格高度,以此来提高UITableView的滚动性能。当UITableView请求某一行的预估高度时,会先从缓存字典中查找,若找到则直接返回该高度,未找到则返回默认高度100;当单元格被展示时,其实际高度会被更新到缓存字典中。
517

被折叠的 条评论
为什么被折叠?



