CollectionView代理方法的介绍

2016-11-17  本文已影响54人  萨瓦迪卡123456

1.这个方法和tableview的一样,返回的是collection中item的个数。

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

2.返回的collection有多少个区

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

3.配置cell,同时也需要注册cell

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

4.这个方法是反回cell是否可以拖拽移动,但是他需要给collection添加长按手势的操作

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

5.这个方法可以自定义collection的headerview和footview,同时呢,我们需要先进行注册

- (__kindof UICollectionReusableView *)dequeueReusableSupplementaryViewOfKind:(NSString *)elementKind withReuseIdentifier:(NSString *)identifier forIndexPath:(NSIndexPath *)indexPath;

6.当cell即将显示的时候调用的方法

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

以上这些方法就是最基本的方法。

上一篇 下一篇

猜你喜欢

热点阅读