iOS 流布局 UICollectionView使用(UICollectionVIew的代理方法)

摘要:
UICollectionViewDataSource协议该协议主要用于处理与collectionView相关的数据。方法如下:设置分区数(这是可选的)-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView*)collectionView;设置每个分区有多少项(必须实现)-(NSInteger)collectio

UICollectionViewDataSource协议

这个协议主要用于collectionView相关数据的处理,包含方法如下:

设置分区数(这个是可选实现的)

- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView;

设置每个分区有多少个item(必须实现)

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

设置返回每个item的属性(必须实现)

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath;

对头视图和尾视图进行设置(如果需要的话)

- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath;

设置某个item是否可以移动 返回NO表示不能移动

- (BOOL)collectionView:(UICollectionView *)collectionView canMoveItemAtIndexPath:(NSIndexPath *)indexPath NS_AVAILABLE_IOS(9_0);

移动item的时候会调用这个方法

- (void)collectionView:(UICollectionView *)collectionView moveItemAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath*)destinationIndexPath;

UICollectionViewDelegate协议

这个协议用来设置和处理collectionView的功能和一些逻辑,所有方法都是可选实现

是否允许某个item的高亮,返回NO 则不能进入高亮状态。

- (BOOL)collectionView:(UICollectionView *)collectionView shouldHighlightItemAtIndexPath:(NSIndexPath *)indexPath;

当item高亮时触发的方法

- (void)collectionView:(UICollectionView *)collectionView didHighlightItemAtIndexPath:(NSIndexPath *)indexPath;

结束高亮时触发的方法

- (void)collectionView:(UICollectionView *)collectionView didUnhighlightItemAtIndexPath:(NSIndexPath *)indexPath;

是否可以选中某个item 返回NO不能选中

- (BOOL)collectionView:(UICollectionView *)collectionView shouldSelectItemAtIndexPath:(NSIndexPath *)indexPath;

是否可以取消选中某个item

- (BOOL)collectionView:(UICollectionView *)collectionView shouldDeselectItemAtIndexPath:(NSIndexPath *)indexPath;

选中某个item触发的方法

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath;

取消选中某个item时触发的方法

- (void)collectionView:(UICollectionView *)collectionView didDeselectItemAtIndexPath:(NSIndexPath *)indexPath;

将要加载头尾视图时调用的方法

- (void)collectionView:(UICollectionView *)collectionView willDisplaySupplementaryView:(UICollectionReusableView *)view forElementKind:(NSString *)elementKind atIndexPath:(NSIndexPath *)indexPath NS_AVAILABLE_IOS(8_0);

已经展示某个Item时触发的方法

- (void)collectionView:(UICollectionView *)collectionView didEndDisplayingCell:(UICollectionViewCell *)cell forItemAtIndexPath:(NSIndexPath *)indexPath;

已经展示某个头尾视图时触发的方法

- (void)collectionView:(UICollectionView *)collectionView didEndDisplayingSupplementaryView:(UICollectionReusableView *)view forElementOfKind:(NSString *)elementKind atIndexPath:(NSIndexPath *)indexPath;

将要加载某个Item时调用的方法

- (void)collectionView:(UICollectionView *)collectionView willDisplayCell:(UICollectionViewCell *)cell forItemAtIndexPath:(NSIndexPath *)indexPath NS_AVAILABLE_IOS(8_0);

这个方法设置是否展示长按菜单

- (BOOL)collectionView:(UICollectionView *)collectionView shouldShowMenuForItemAtIndexPath:(NSIndexPath *)indexPath;

这个方法用于设置要展示的菜单选项

- (BOOL)collectionView:(UICollectionView *)collectionView canPerformAction:(SEL)action forItemAtIndexPath:(NSIndexPath *)indexPath withSender:(nullable id)sender;

这个方法用于实现点击菜单按钮后的触发方法,通过测试,只有copy,cut和paste三个方法可以使用

- (void)collectionView:(UICollectionView *)collectionView performAction:(SEL)action forItemAtIndexPath:(NSIndexPath *)indexPath withSender:(nullable id)sender;

collectionView进行重新布局时调用的方法

- (nonnull UICollectionViewTransitionLayout *)collectionView:(UICollectionView *)collectionView transitionLayoutForOldLayout:(UICollectionViewLayout *)fromLayout newLayout:(UICollectionViewLayout *)toLayout;

免责声明:文章转载自《iOS 流布局 UICollectionView使用(UICollectionVIew的代理方法)》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇APScheduler 增加作业 add_job11springboot的MVC配置原理下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

汇集移动端兼容性问题

1、一些情况下对非可点击元素如(label,span)监听click事件,ios下不会触发 css增加cursor:pointer 2、三星手机遮罩层下的input、select、a等元素可以被点击和focus(点击穿透) 发现于三星手机,这个在特定需求下才会有,因此如果没有类似问题的可以不看。首先需求是浮层操作,在三星上被遮罩的元素依然可以获取focu...

solr6.6初探之查询篇

关于搜索与查询,首先我们来看一张图: 这张图说明了solr查询原理: 1.当通过solr发起查询的时候,引擎会选择一个RequestHandler(从字面意思上来说就是请求处理器)来进行查询处理 2.查询的请求处理器会选择一个查询解析器来解析查询参数(语法 3.solr会根据查询列在索引中搜索存储字段,默认是全部 4.根据偏移量及数据量(start,ro...

在notepad++中markdown高亮并实时预览

在notepad++中markdown高亮并实时预览 markdown是一种非常简洁、高效的标记语言,非常适合写博客、随笔,越来越受到大家欢迎。同时notepad++是Windows系统下使用非常广泛文本编辑器,但是非常遗憾的是otepad不默认支持markdown,但是感谢各位开发者,我们可以在notepad中使用markdown,并且能够实时预览。有的...

vim学习3-《Vim实用技巧》

注:<C-o>代表 按着Ctrl+o   其他 删除 J  - join line 。删除空白行  xp 调换两个字符的位置   查找并跳转   查找光标所在的单词,“*”  next identifier  , ";" 下一个。 ","上一个   复制   y$  复制到光标所在位置到该行最后一个字符。 "+y  复制选中内容到+寄存器,也...

VIM C语言函数名高亮

VIM默认情况下,函数名是不会高亮的,将下面这段代码添加到/usr/share/vim/vim73/syntax/c.vim文件的末尾即可: "highlight Functions syn match cFunctions "<[a-zA-Z_][a-zA-Z_0-9]*>[^()]*)("me=e-2 syn match cFunctio...

IOS开发之UIColectionView

      UICollectionView 和 UICollectionViewController 类是iOS6 新引进的API,用于展示集合视图,布局更加灵活,可实现多列布局,用法类似于UITableView 和 UITableViewController 类。      使用UICollectionView 必须实现UICollectionView...