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

     

     

     

  • 相关阅读:
    数组的push()、pop()、shift()和unshift()方法
    Javascript的函数柯里化
    开闭原则
    字符串相等的判断
    String类常用的方法
    阅读API文档
    String类和常量池
    String基础
    内部类的分类
    内部类的概念
  • 原文地址:https://www.cnblogs.com/studyios/p/3592897.html
Copyright © 2011-2022 走看看