zoukankan      html  css  js  c++  java
  • iOS 流布局 UICollectionView使用(UICollectionVIew的代理方法)

    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;
  • 相关阅读:
    使用 Hudson 进行持续集成
    hudson中的ftp插件
    Tomcat i18n 对 URL 进行 UTF8 解码
    Product deploy using NAnt and NSIS [技术点滴]
    切身体会到对微软的无语——关于VS2008的配置项
    How to create your own home SVN repository with Xampp/Apache
    CVS+VS2003+SetupFactory建设每日构建(Daily build)
    期待 JDK、Tomcat和MySQL的绿色安装方法
    FolderBrowserDialog 使用时路径问题
    无敌删除命令
  • 原文地址:https://www.cnblogs.com/huanying2000/p/6491911.html
Copyright © 2011-2022 走看看