tableView的优化方法

一、异步加载图片:html

     在ios

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

方法中这样判断:缓存

if (tableView.dragging == NO && tableView.decelerating == NO) {
    //异步加载图片
}

而且在异步

-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView

优化

-(void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate

方法中进行异步加载图片spa

二、缓存cell高度,实现cell高度计算与cell的内容展现的分离.net

    具体实现就是在cell的数据模型中计算cell所需高度,为数据模型增长一个高度的属性,计算完成后赋值,而后在code

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath

中取出cell相应模型中的高度,赋值,而在htm

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

中只负责cell内容的展现,再也不负责计算。图片

参考连接:

tableView优化

tableView优化2


三、当每一行的cell高度一致的时候使用属性设置cell的高度

// 当每一行的cell高度一致的时候使用属性设置cell的高度     
   self.tableView.rowHeight = 160;

四、减小不透明视图的使用

      不透明的视图能够极大地提升渲染的速度。所以如非必要,能够将table cell及其子视图的opaque属性设为YES(默认值)。
其中的特例包括背景色,它的alpha值应该为1(例如不要使用clearColor);图像的alpha值也应该为1,或者在画图时设为不透明。

五、绘制

参考:预渲染加速图像的显示

相关文章
相关标签/搜索