zoukankan      html  css  js  c++  java
  • cell重用的几种方式

    1.使用xib重用

     //ios6 之后推荐大家使用的重用方式

        //动态的使用self获得当前类名,来作为唯一的标示

        NSString * identifier = NSStringFromClass([self class]);

        UINib * nib = [UINib nibWithNibName:identifier bundle:nil];

             //注册

        [tableView registerNib:nib forCellReuseIdentifier:identifier];

        

        //先在缓存池中去,如果缓存池没有可重用的cell,那么根据前面注册的nib创建一个cell对象给你返回回来

        GPSubjectCell * cell = [tableView dequeueReusableCellWithIdentifier:identifier];

        

        return cell;

    2,纯代码

        //保证标示的唯一性,使用类名是一种非常好的选择

        

        NSString * identifier = @"GPSubjectCell";

        

        //1.先去缓存池中找是否有可以重用的

        GPSubjectCell * cell = [tableView dequeueReusableCellWithIdentifier:identifier];

        //2.如果没有可以重用的那么自己创建一个出来

        if(cell == nil)

        {

            cell = [[self alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];

        }

        

        return cell;

    3.

    //使用注册的机制,实现纯代码cell类的重用

        NSString * className = NSStringFromClass([self class]);

        [tableView registerClass:[self class] forCellReuseIdentifier:className];

        return [tableView dequeueReusableCellWithIdentifier:className];

    4.使用storyboard 时, (但必须给cell一个Identifier)

    return  [collectionView dequeueReusableCellWithReuseIdentifier:@"bookCell" forIndexPath:indexPath];

  • 相关阅读:
    华为机试题01背包问题
    丑数
    动态规划(1)
    Linux 后台启动 Redis
    redis.exceptions.ResponseError: MISCONF Redis is configured to save RDB snapshots, but is currently not able to persist on disk.
    SQLServer从渣仔到小白
    cmder 增强型命令行工具
    总结在部署分布式爬虫环境过程中常见的若干问题
    【pymongo.errors】Cursor not found
    浅析scrapy与scrapy_redis区别
  • 原文地址:https://www.cnblogs.com/ouyangxiaoyao/p/5663393.html
Copyright © 2011-2022 走看看