首页 > 其他 > 详细

cell 重用

时间:2014-03-11 15:44:17      阅读:511      评论:0      收藏:0      [点我收藏+]

 1. 当单元格因滚屏而脱落表格可见区时,表格可以将其缓存到重用队列中。

       用法:我们可标记单元格以备重用,然后根据需要从该队列中提取。

         在分配新单元格时,必须检查重用单元格是否可用。如果表格对dequeueReusableCellWithIndentifier:的请求返回nil,那么就需  要分配一个新的单元格。  

        static NSString *CellIdentifier = @"Cell";

      UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];

   我们一般会改成

static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier ];

    if (!cell) {

          UITableViewCell *cell = [[UITableViewCellalloc]initWithStyle:UITableViewCellStyleDefaultreuseIdentifier:CellIdentifier];

  }

 

2.如果用默认的方法则需要用下面两个方法的任意一个

    - (void)registerNib:(UINib *)nib forCellReuseIdentifier:(NSString *)identifier ;

    - (void)registerClass:(Class)cellClass forCellReuseIdentifier:(NSString *)identifier ;

  先注册一个   

     [self.tableView registerClass:[CustomCell Class] forCellReuseIdentifier:@"CustomCell"];

而只需要 UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];

cell 重用,布布扣,bubuko.com

cell 重用

原文:http://www.cnblogs.com/studyios/p/3592897.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!