美文网首页
tableview的一种缓存高度方法

tableview的一种缓存高度方法

作者: 参天草 | 来源:发表于2018-07-03 10:49 被阅读0次

@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];

}

相关文章

网友评论

      本文标题:tableview的一种缓存高度方法

      本文链接:https://www.haomeiwen.com/subject/nyjduftx.html