zoukankan      html  css  js  c++  java
  • cell 重用

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

     

     

     

  • 相关阅读:
    Mybatis框架学习02
    第四周学习进度
    第四周安卓开发学习总结(2)
    第四周安卓开发学习总结(1)
    使用Python进行疫情数据爬取
    使用Jsoup进行疫情数据爬取
    Mybatis框架学习01
    第三周学习进度
    第三周安卓开发学习总结
    全国疫情统计地图可视化(2)——实现数据下钻
  • 原文地址:https://www.cnblogs.com/studyios/p/3592897.html
Copyright © 2011-2022 走看看