陈述一下简单流程:

1.首先定义:UICollectionViewFlowLayout

2.初始化UICollectionView

3.注册复用的cell,定义她们的reuseIndefinite

4.注册UICollectionView的delegate和DataSource代理

5.完成代理,ok

代码:

- (UICollectionView *)collectionView
{
    if (!_collectionView)
    {
        UICollectionViewFlowLayout * layout = [[UICollectionViewFlowLayout alloc] init];
        layout.minimumLineSpacing      = I_P_SP;
        layout.minimumInteritemSpacing = I_P_I_SP;
        layout.scrollDirection         = UICollectionViewScrollDirectionHorizontal;

        _collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(, , self.width, )  collectionViewLayout:layout];
        _collectionView.backgroundColor = def_color_white;
        [_collectionView registerClass:[IssuePhotosViewCell class] forCellWithReuseIdentifier:kPhotoCellIdentifier];
        [_collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:kAddCellIdentifier];

        _collectionView.delegate                       = self;
        _collectionView.dataSource                     = self;
        _collectionView.showsHorizontalScrollIndicator = NO;
        _collectionView.showsVerticalScrollIndicator   = NO;

        [self addSubview:_collectionView];
    }
    return _collectionView;
}

UICollectionView的Lazy Load

#pragma mark - UICollectionViewDelegate / DataSource / FlowLayout

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
    , );
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    // TODO 图片浏览器

    NSLog(@"%ld",(long)[indexPath row]);
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    ;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row == [self.assetsArray count])
    {
        UICollectionViewCell * cell = [collectionView dequeueReusableCellWithReuseIdentifier:kAddCellIdentifier forIndexPath:indexPath];
        [cell.contentView addSubview:self.addButton];
        return cell;
    }
    else
    {
        IssuePhotosViewCell * cell = [collectionView dequeueReusableCellWithReuseIdentifier:kPhotoCellIdentifier forIndexPath:indexPath];
        cell.asset                 = [self.assetsArray objectAtIndex:indexPath.row];
        cell.indexPath             = indexPath;
        cell.deletePhotoButton.tag = indexPath.row;
        [cell.deletePhotoButton addTarget:self action:@selector(deleteView:) forControlEvents:UIControlEventTouchUpInside];

        return cell;
    }

UICollectionView的代理实现

复用问题,只要把界面和数据分开处理即可,界面初始化写在自定cell或者系统cell的初始化中,数据则每次重新更新即可

【项目】UICollectionView 对象自定的更多相关文章

  1. 基于 abp vNext 和 .NET Core 开发博客项目 - 用AutoMapper搞定对象映射

    上一篇文章(https://www.cnblogs.com/meowv/p/12961014.html)集成了定时任务处理框架Hangfire,完成了一个简单的定时任务处理解决方案. 本篇紧接着来玩一 ...

  2. 在.net core 的webapi项目中将对象序列化成json

    问题:vs2017 15.7.6创建一个基于.net core 2.1的webapi项目,默认生成的控制器继承自ControllerBase类 在此情况下无法使用Json()方法 将一个对象转成jso ...

  3. 关于C++项目指针对象未被初始化的问题(0xcdcdcd)

    http://blog.csdn.net/devfun/article/details/6900086 昨天我试图将一个封装好的模块加入到正在开发的项目中,这个模块不是单独的类,而且对应的声明和实例. ...

  4. 用面对对象方式定tab标签

    一些公共的底层的JS方法 var GLOBAL = {}; GLOBAL.namespace = function (str) { var arr = str.split('.'), o = GLOB ...

  5. 【开源项目SugarSite】ASP.NET MVC+ Layui+ SqlSugar+RestSharp项目讲解

    SugarSite一个前端支持移动端的企业网站,目前只支持了简单功能,后续还会加上论坛等. 源码GIT地址: https://github.com/sunkaixuan/SugarSite 技术介绍 ...

  6. 在vue中使用基于d3为基础的dagre-d3.js搞定一个流程图组件

    项目中想搞定一个流程图,开始使用了阿里的G6,但是G6目前不支持手势,这样就很郁闷了,因为公司的领导都是使用iPad看的,你不支持手势是不行的,后来又想到了百度的echarts,试了试,感觉还不错,手 ...

  7. 基于 abp vNext 和 .NET Core 开发博客项目 - 博客接口实战篇(一)

    系列文章 基于 abp vNext 和 .NET Core 开发博客项目 - 使用 abp cli 搭建项目 基于 abp vNext 和 .NET Core 开发博客项目 - 给项目瘦身,让它跑起来 ...

  8. 基于 abp vNext 和 .NET Core 开发博客项目 - 博客接口实战篇(二)

    系列文章 基于 abp vNext 和 .NET Core 开发博客项目 - 使用 abp cli 搭建项目 基于 abp vNext 和 .NET Core 开发博客项目 - 给项目瘦身,让它跑起来 ...

  9. 基于 abp vNext 和 .NET Core 开发博客项目 - 博客接口实战篇(三)

    系列文章 基于 abp vNext 和 .NET Core 开发博客项目 - 使用 abp cli 搭建项目 基于 abp vNext 和 .NET Core 开发博客项目 - 给项目瘦身,让它跑起来 ...

随机推荐

  1. Bootstrap系列 -- 4. 文本内容强调

    一. 文本强调基本样式 .text-muted:提示,使用浅灰色(#999) .text-primary:主要,使用蓝色(#428bca) .text-success:成功,使用浅绿色(#3c763d ...

  2. js的一些冷门的用法

    1.delete 2.void 0 3.>>> 4.>>0 字符串转为数字 5.[] == ![] 6.

  3. dinic模板

    procedure addedge(u,v,cap:longint); begin sid[tot].u:=u; sid[tot].v:=v; sid[tot].cap:=cap; sid[tot]. ...

  4. Javascript/jQuery 获取地址栏URL参数的方法

    1.jquery获取url很简单,代码如下 window.location.href; 2.javascript获取url参数 function getUrlParam(name) { var reg ...

  5. JavaScript的理解记录(4)

    客户端JavaScript:客户端就是Web浏览器; 一. 前奏: Web文档(document):一些呈现静态信息的页面,虽然有的页面是会动的,但信息本身还是静态! Web应用:可以动态载入信息,相 ...

  6. CMD命令简单使用

    1.定位磁盘 2.打开文件路径 3.查看文件目录里面所有的文件或目录信息

  7. 前端 head 中mate 详解

    <meta name="viewport" content="width=device-width,height=device-height,initial-sca ...

  8. 查询和修改(Queries and Mutations)

    On this page, you'll learn in detail about how to query a GraphQL server. 在这个页面,你将会学习更多的关于如何查询GraphQ ...

  9. px和em和rem的区别

    一.px特点: 1. IE无法调整那些使用px作为单位的字体大小: 2. 国外的大部分网站能够调整的原因在于其使用了em或rem作为字体单位: 3. Firefox能够调整px和em,rem,但是96 ...

  10. 写启动界面Splash的正确姿势,解决启动白屏(转)

    原文链接:http://www.jianshu.com/p/cd6ef8d3d74d 从我学习写第一个android项目以来,我都是这样写着启动界面: 在里面做一些事,比如:第一次启动时拷贝数据. 然 ...