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

  • 相关阅读:
    Git 安装
    golang学习笔记--struct同时用于bson json
    golang学习笔记--struct、json、map互相转化
    IDEA关联不同项目源码
    xss攻击atob
    maven设置编辑级别,设置编码来源
    AppleScript创建新文件
    Java线程池吃掉异常整理
    docker 启动中间件整理
    docker container启动之后 命令更新
  • 原文地址:https://www.cnblogs.com/ouyangxiaoyao/p/5663393.html
Copyright © 2011-2022 走看看