码迷,mamicode.com
首页 > 其他好文 > 详细

UITableview优化

时间:2016-04-04 19:46:24      阅读:171      评论:0      收藏:0      [点我收藏+]

标签:

说明:

  • 开始只创建一部分可见的cell(已由Xcode实现)
  • 在滚动的时候,先去缓存池中查找可用的cell,如果有,则取出使用

优化的两种方法

  • 方法1:在创建cell时先去缓存池找是否有可用的cell
    NSString *ID=@"test";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    if(cell==nil){
        cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:ID];
    }
    cell.textLabel.text=[NSString stringWithFormat:@"test%zd",indexPath.row];
  • 方法2:注册cell
    //在viewDidLoad方法注册cell,注册一次即可
    [tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:ID];

    //注册之后效果同方法1
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    cell.textLabel.text=[NSString stringWithFormat:@"test%zd",indexPath.row];

UITableview优化

标签:

原文地址:http://www.cnblogs.com/JavaTWW/p/5352626.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!