|
| 1 | +// |
| 2 | +// ZHAutoConfigurationCollectionViewDelegate.m |
| 3 | +// Pods |
| 4 | +// |
| 5 | +// Created by 张行 on 2017/4/20. |
| 6 | +// |
| 7 | +// |
| 8 | + |
| 9 | +#import "ZHAutoConfigurationCollectionViewDelegate.h" |
| 10 | +#import "ZHCollectionViewDataSource.h" |
| 11 | + |
| 12 | +@implementation ZHAutoConfigurationCollectionViewDelegate { |
| 13 | + ZHCollectionViewDataSource *_dataSource; |
| 14 | +} |
| 15 | + |
| 16 | +- (instancetype)initWithDataSource:(ZHCollectionViewDataSource *)dataSource { |
| 17 | + if (self = [super init]) { |
| 18 | + _dataSource = dataSource; |
| 19 | + } |
| 20 | + return self; |
| 21 | +} |
| 22 | + |
| 23 | +- (ZHCollectionViewDataSourceCustomHeightCompletionHandle)completionHandleWithCollectionView:(UICollectionView *)collectionView heightAtIndexPath:(NSIndexPath *)indexPath { |
| 24 | + ZHCollectionViewDataSourceCustomHeightCompletionHandle completionHandle = ^CGFloat(ZHCollectionViewBaseModel *model) { |
| 25 | + if (!model.customHeightCompletionHandle) { |
| 26 | + return model.height; |
| 27 | + } |
| 28 | + return model.customHeightCompletionHandle(collectionView,[ZHCollectionViewDataSource indexPathWithDataSource:_dataSource indexPath:indexPath],model); |
| 29 | + }; |
| 30 | + return completionHandle; |
| 31 | +} |
| 32 | + |
| 33 | +- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView { |
| 34 | + return [ZHCollectionViewDataSource numberOfSectionsWithDataSource:_dataSource]; |
| 35 | +} |
| 36 | + |
| 37 | +- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { |
| 38 | + return [ZHCollectionViewDataSource cellForRowAtWithDataSource:_dataSource indexPath:indexPath]; |
| 39 | +} |
| 40 | + |
| 41 | +- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section { |
| 42 | + return [ZHCollectionViewDataSource numberOfRowsInSectionWithDataSource:_dataSource section:section]; |
| 43 | +} |
| 44 | + |
| 45 | +- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath { |
| 46 | + if ([kind isEqualToString:UICollectionElementKindSectionHeader]) { |
| 47 | + return [ZHCollectionViewDataSource viewForHeaderInSectionWithDataSource:_dataSource section:indexPath.section]; |
| 48 | + } else { |
| 49 | + return [ZHCollectionViewDataSource viewForFooterInSectionWithDataSource:_dataSource section:indexPath.section]; |
| 50 | + } |
| 51 | +} |
| 52 | + |
| 53 | +- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath { |
| 54 | + [collectionView deselectItemAtIndexPath:indexPath animated:YES]; |
| 55 | + [ZHCollectionViewDataSource didSelectRowAtWithDataSource:_dataSource indexPath:indexPath]; |
| 56 | +} |
| 57 | + |
| 58 | +- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath { |
| 59 | + return CGSizeZero; |
| 60 | +} |
| 61 | + |
| 62 | +- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section { |
| 63 | + return CGSizeZero; |
| 64 | +} |
| 65 | + |
| 66 | +- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForFooterInSection:(NSInteger)section { |
| 67 | + return CGSizeZero; |
| 68 | +} |
| 69 | + |
| 70 | +@end |
| 71 | + |
0 commit comments