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

  • 相关阅读:
    c# 调用CMD窗口执行命令
    WPF 添加阴影效果
    WPF中鼠标拖动窗体
    c# exe程序只让启动一个
    $.when().done().then()的用法
    Math.round(),Math.ceil(),Math.floor()取整计算
    面向对象的程序设计-继承
    MATLAB | 直接保存窗口图片而不弹出figure窗口
    MATLAB 小tips总结
    图像数字处理 | Bit-Plane Slicing 比特平面分层- 如何计算
  • 原文地址:https://www.cnblogs.com/ouyangxiaoyao/p/5663393.html
Copyright © 2011-2022 走看看