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

  • 相关阅读:
    初学JS——利用JS制作的别踩白块儿(街机模式) 小游戏
    对于大数据量的Json解析
    Json数据中的特殊字符处理
    移动端总结和手机兼容问题
    在DW 5.5+PhoneGap+Jquery Mobile下搭建移动开发环境
    HTML5所有标签汇总
    二叉树
    二分查找
    归并排序
    希尔排序
  • 原文地址:https://www.cnblogs.com/ouyangxiaoyao/p/5663393.html
Copyright © 2011-2022 走看看