【项目】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 开发博客项目 - 给项目瘦身,让它跑起来 ...
随机推荐
- Oracle基础语法
--表create table tb_myTable( mname vardhar2(30), pwd varchar2(30)); --存储过程create or replace procedure ...
- learning to rank
Learning to Rank入门小结 + 漫谈 Learning to Rank入门小结 Table of Contents 1 前言 2 LTR流程 3 训练数据的获取4 特征抽取 3.1 人工 ...
- 关于iphone 6 ios8网站背景图片错乱的问题解决办法
最近公司有个客户的网站用手机safari打开出现背景图片错乱,本来应该显示A图片的却显示B图片,网速越慢的情况下越容易出现这种问题,悲催的是这种情况只在iPhone 6上出现,并且不是一直这样,多刷新 ...
- C语言输入输出整数
scanf("%llu", &x); printf("%llu\n", x); scanf("%u", &x); print ...
- jq mobile非ajax加载,ready执行两次
jqm只有通过ajax加载的页面才只执行一次ready(正常情况) 页面刷新(同非ajax加载的页面)都会执行两次ready,包括pageinit和pageshow事件也是如此. 两种避免的方法是: ...
- ASP.NET中实现Session的负载均衡
据我目前所知有2种方法,如下: 1.利用微软提供的解决方案 参考网址:http://blog.maartenballiauw.be/post/2008/01/23/ASPNET-Session-Sta ...
- python 2.7 和3.0input区别
name = raw_input('请输入用户名:')#python2.7的用法 name = input('请输入用户名:')#python3.0的用法 print(name)
- Oracle Temp表空间切换
来源于: http://www.2cto.com/database/201507/418564.html 一.TEMP表空间作用 临时表空间主要用途是在数据库进行排序运算.管理索引.访问视图等操作时 ...
- Java设计模式(二) 观察者模式
观察者模式: 定义了对象之间的一对多依赖,这样一来,当一个对象改变状态时,他的所有依赖者都会受到通知并自动更新. 1,定义事件源接口 package com.pattern.observer; pub ...
- 【PKUSC 2015的一道数学题】
有9个人,每三个人中至少有两个互相认识,求证这里面至少有4个人互相认识 PKU官方题解: 引理:二染色K6中一定有同色K3. 证明:考虑某一个点,它一定连出至少三条同色边(不妨设为红边),这三条边连的 ...