首页 > 其他 > 详细

UITableview优化

时间:2016-04-04 19:46:04      阅读:435      评论: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
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!