陈述一下简单流程:

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. 必须要会的技能(一) 如何实现设计时Binding

    今天我们来分享一个主题:DesignTime Binding设计时绑定. 这一项技术可以使用在所有包括WPF及其衍生出来的技术上,比如Sliverlight,当然也包括UWP 先来说明一下设计时Bin ...

  2. [BZOJ1188][HNOI2007]分裂游戏(博弈论)

    题目:http://www.lydsy.com:808/JudgeOnline/problem.php?id=1188 分析: 设SG[i]表示一个石子在位置i上的SG值 这个很容易暴力求,因为i的后 ...

  3. Python 一些总结和比较

    数据类型

  4. 如何在word中的第3+n页处插入页面并重新从1开始

    在插入页码时有时可能会遇到这种情况: word的第一页是文档名称 第二页是目录 第三页才开始是正文,而我们希望看到页码从第三页开始才是第1页. 在第三页的开头,插入分隔符“下一页”,如果office2 ...

  5. Android中this、super的区别

    转载:http://blog.csdn.net/dyllove98/article/details/8826232 在Java中,this通常指当前对象,super则指父类的.当你想要引用当前对象的某 ...

  6. MyBatis学习--简单的增删改查

    jdbc程序 在学习MyBatis的时候先简单了解下JDBC编程的方式,我们以一个简单的查询为例,使用JDBC编程,如下: Public static void main(String[] args) ...

  7. OkHttp 3.4入门

    OkHttp 3.4入门 配置方法 (一)导入Jar包http://repo1.maven.org/maven2/com/squareup/okhttp3/okhttp/3.4.0-RC1/okhtt ...

  8. SPI协议及工作原理分析

    说明.文章摘自:SPI协议及其工作原理分析 http://blog.csdn.net/skyflying2012/article/details/11710801 一.概述. SPI, Serial ...

  9. Fresco内存机制(Ashmem匿名共享内存)

    Fresco的内存机制 Fresco是Facebook出品的高性能图片加载库,采用了Ashmem匿名共享内存机制, 来解决图片加载中的OOM问题.这里不对Fresco做深入分析,只关注Fresco在A ...

  10. WordPress菜单函数wp_nav_menu()详细介绍

    导航菜单函数wp_nav_menu()进行详细的说明. 1.wp_nav_menu()函数介绍: worpdress发展到3.0以后增加了一个自定义菜单函数wp_nav_menu(),使得wordpr ...