【项目】UICollectionView 对象自定
陈述一下简单流程:
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 对象自定的更多相关文章
- 基于 abp vNext 和 .NET Core 开发博客项目 - 用AutoMapper搞定对象映射
上一篇文章(https://www.cnblogs.com/meowv/p/12961014.html)集成了定时任务处理框架Hangfire,完成了一个简单的定时任务处理解决方案. 本篇紧接着来玩一 ...
- 在.net core 的webapi项目中将对象序列化成json
问题:vs2017 15.7.6创建一个基于.net core 2.1的webapi项目,默认生成的控制器继承自ControllerBase类 在此情况下无法使用Json()方法 将一个对象转成jso ...
- 关于C++项目指针对象未被初始化的问题(0xcdcdcd)
http://blog.csdn.net/devfun/article/details/6900086 昨天我试图将一个封装好的模块加入到正在开发的项目中,这个模块不是单独的类,而且对应的声明和实例. ...
- 用面对对象方式定tab标签
一些公共的底层的JS方法 var GLOBAL = {}; GLOBAL.namespace = function (str) { var arr = str.split('.'), o = GLOB ...
- 【开源项目SugarSite】ASP.NET MVC+ Layui+ SqlSugar+RestSharp项目讲解
SugarSite一个前端支持移动端的企业网站,目前只支持了简单功能,后续还会加上论坛等. 源码GIT地址: https://github.com/sunkaixuan/SugarSite 技术介绍 ...
- 在vue中使用基于d3为基础的dagre-d3.js搞定一个流程图组件
项目中想搞定一个流程图,开始使用了阿里的G6,但是G6目前不支持手势,这样就很郁闷了,因为公司的领导都是使用iPad看的,你不支持手势是不行的,后来又想到了百度的echarts,试了试,感觉还不错,手 ...
- 基于 abp vNext 和 .NET Core 开发博客项目 - 博客接口实战篇(一)
系列文章 基于 abp vNext 和 .NET Core 开发博客项目 - 使用 abp cli 搭建项目 基于 abp vNext 和 .NET Core 开发博客项目 - 给项目瘦身,让它跑起来 ...
- 基于 abp vNext 和 .NET Core 开发博客项目 - 博客接口实战篇(二)
系列文章 基于 abp vNext 和 .NET Core 开发博客项目 - 使用 abp cli 搭建项目 基于 abp vNext 和 .NET Core 开发博客项目 - 给项目瘦身,让它跑起来 ...
- 基于 abp vNext 和 .NET Core 开发博客项目 - 博客接口实战篇(三)
系列文章 基于 abp vNext 和 .NET Core 开发博客项目 - 使用 abp cli 搭建项目 基于 abp vNext 和 .NET Core 开发博客项目 - 给项目瘦身,让它跑起来 ...
随机推荐
- 阿里云Ubuntu 14.04 + Nginx + let's encrypt 搭建https访问
参考页面: https://certbot.eff.org/#ubuntutrusty-nginx http://bbs.qcloud.com/thread-12059-1-1.html http:/ ...
- Linux进程间通信之信号量
春节过去了,真的过去一年了.在公司待了快一年了.2016希望自己变得越来越好. ps:上面那句话是年前写的,中间隔了那么久,自己也变懒了. 一.信号量 1,信号量本质是一个计数器,控制访问共享资源的最 ...
- 三言两语聊Python模块–文档测试模块doctest
doctest是属于测试模块里的一种,对注释文档里的示例进行检测. 给出一个例子: splitter.pydef split(line, types=None, delimiter=None): &q ...
- getContentResolver()内容解析者查询联系人、插入联系人
首先,我们需要知道的两个Uri: 1.Uri uri = Uri.parse("content://com.android.contacts/raw_contacts");//查到 ...
- memcached安装配置
简述: memcached,开源的分布式缓存数据系统.高性能的NOSQL . Linux 一.环境配置与安装 01.编译准备环境 yum install -y gcc make cmake autoc ...
- 消息队列写入内容后,读出来的自动包裹了<string>标签,自定义格式化器解决该issue
/// <summary> /// 该格式化器使输入即输出 /// </summary> public class StringFormatter : IMessageForm ...
- Fragment 与Activity之间的通信
1.Fragment-->Activity 在fragment中的onAttach()中引用Activity实现的接口实例. 2Activity-->Fragment 直接调用 3多个Fr ...
- 顺序队列的C语言实现
#include <stdio.h> #define MAXSIZE 101 #define ELEMTYPE int #define QUEUE_EMPTY -10000 typedef ...
- [Google Guava]学习--新集合类型Multiset
Guava提供了一个新集合类型Multiset,它可以多次添加相等的元素,且和元素顺序无关.Multiset继承于JDK的Cllection接口,而不是Set接口. Multiset主要方法介绍: a ...
- 【BZOJ 1503】【NOI 2004】郁闷的出纳员
$Splay$模板题. 复习一下伸展树的模板. 一定不要忘了push啊!!! 对于减工资后删掉员工的操作,我选择插入一个$min+delta_{减少的工资}$的节点,把它$Splay$到根,砍掉它自己 ...