-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from josercc/developer-josercc
Developer josercc
- Loading branch information
Showing
28 changed files
with
1,111 additions
and
31 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Empty file.
Empty file.
34 changes: 34 additions & 0 deletions
34
ZHTableViewGroup/Classes/ZHAutoConfigurationCollectionViewDelegate.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// | ||
// ZHAutoConfigurationCollectionViewDelegate.h | ||
// Pods | ||
// | ||
// Created by 张行 on 2017/4/20. | ||
// | ||
// | ||
|
||
#import <Foundation/Foundation.h> | ||
|
||
typedef NS_ENUM(NSUInteger, ZHCollectionViewCustomHeightType) { | ||
ZHCollectionViewCustomHeightTypeCell, | ||
ZHCollectionViewCustomHeightTypeHeader, | ||
ZHCollectionViewCustomHeightTypeFooter | ||
}; | ||
|
||
@class ZHCollectionViewDataSource; | ||
|
||
/** | ||
自动配置 UICollectionView 的数据源和代理 | ||
默认实现 UICollectionView 的数据源方法和代理方法如下 | ||
*/ | ||
@interface ZHAutoConfigurationCollectionViewDelegate : NSObject <UICollectionViewDataSource, UICollectionViewDelegate, UICollectionViewDelegateFlowLayout> | ||
|
||
/** | ||
初始化自动配置ZHAutoConfigurationCollectionViewDelegate对象 | ||
@param dataSource ZHCollectionViewDataSource | ||
@return ZHAutoConfigurationCollectionViewDelegate | ||
*/ | ||
- (instancetype)initWithDataSource:(ZHCollectionViewDataSource *)dataSource; | ||
|
||
@end | ||
|
71 changes: 71 additions & 0 deletions
71
ZHTableViewGroup/Classes/ZHAutoConfigurationCollectionViewDelegate.m
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
// | ||
// ZHAutoConfigurationCollectionViewDelegate.m | ||
// Pods | ||
// | ||
// Created by 张行 on 2017/4/20. | ||
// | ||
// | ||
|
||
#import "ZHAutoConfigurationCollectionViewDelegate.h" | ||
#import "ZHCollectionViewDataSource.h" | ||
|
||
@implementation ZHAutoConfigurationCollectionViewDelegate { | ||
ZHCollectionViewDataSource *_dataSource; | ||
} | ||
|
||
- (instancetype)initWithDataSource:(ZHCollectionViewDataSource *)dataSource { | ||
if (self = [super init]) { | ||
_dataSource = dataSource; | ||
} | ||
return self; | ||
} | ||
|
||
- (ZHCollectionViewDataSourceCustomHeightCompletionHandle)completionHandleWithCollectionView:(UICollectionView *)collectionView heightAtIndexPath:(NSIndexPath *)indexPath { | ||
ZHCollectionViewDataSourceCustomHeightCompletionHandle completionHandle = ^CGFloat(ZHCollectionViewBaseModel *model) { | ||
if (!model.customHeightCompletionHandle) { | ||
return model.height; | ||
} | ||
return model.customHeightCompletionHandle(collectionView,[ZHCollectionViewDataSource indexPathWithDataSource:_dataSource indexPath:indexPath],model); | ||
}; | ||
return completionHandle; | ||
} | ||
|
||
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView { | ||
return [ZHCollectionViewDataSource numberOfSectionsWithDataSource:_dataSource]; | ||
} | ||
|
||
- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { | ||
return [ZHCollectionViewDataSource cellForRowAtWithDataSource:_dataSource indexPath:indexPath]; | ||
} | ||
|
||
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section { | ||
return [ZHCollectionViewDataSource numberOfRowsInSectionWithDataSource:_dataSource section:section]; | ||
} | ||
|
||
- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath { | ||
if ([kind isEqualToString:UICollectionElementKindSectionHeader]) { | ||
return [ZHCollectionViewDataSource viewForHeaderInSectionWithDataSource:_dataSource section:indexPath.section]; | ||
} else { | ||
return [ZHCollectionViewDataSource viewForFooterInSectionWithDataSource:_dataSource section:indexPath.section]; | ||
} | ||
} | ||
|
||
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath { | ||
[collectionView deselectItemAtIndexPath:indexPath animated:YES]; | ||
[ZHCollectionViewDataSource didSelectRowAtWithDataSource:_dataSource indexPath:indexPath]; | ||
} | ||
|
||
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath { | ||
return CGSizeZero; | ||
} | ||
|
||
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section { | ||
return CGSizeZero; | ||
} | ||
|
||
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForFooterInSection:(NSInteger)section { | ||
return CGSizeZero; | ||
} | ||
|
||
@end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// | ||
// ZHCollectionViewBaseModel.h | ||
// Pods | ||
// | ||
// Created by 张行 on 2018/2/6. | ||
// | ||
// | ||
|
||
@class ZHCollectionViewBaseModel; | ||
|
||
typedef CGFloat (^ZHCollectionViewBaseModelCustomHeightCompletionHandle)(UICollectionView *collectionView, NSIndexPath *indexPath, ZHCollectionViewBaseModel *model); | ||
|
||
/** | ||
配置 Cell Header Footer 的数据 Model | ||
*/ | ||
@interface ZHCollectionViewBaseModel : NSObject | ||
|
||
/** | ||
标识符 | ||
*/ | ||
@property (nonatomic, copy) NSString *identifier; | ||
/** | ||
自定义类 Class | ||
*/ | ||
@property (nonatomic, strong) Class anyClass; | ||
/** | ||
高度 默认为 NSNotFound | ||
*/ | ||
@property (nonatomic, assign) CGFloat height; | ||
/** | ||
* 自定义高度 | ||
*/ | ||
@property (nonatomic, copy) ZHCollectionViewBaseModelCustomHeightCompletionHandle customHeightCompletionHandle; | ||
|
||
@end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// | ||
// ZHCollectionViewBaseModel.m | ||
// Pods | ||
// | ||
// Created by 张行 on 2018/2/6. | ||
// | ||
// | ||
|
||
#import "ZHCollectionViewBaseModel.h" | ||
|
||
@implementation ZHCollectionViewBaseModel | ||
|
||
- (instancetype)init { | ||
if (self = [super init]) { | ||
_height = NSNotFound; | ||
} | ||
return self; | ||
} | ||
|
||
@end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
// | ||
// | ||
// ZHCollectionViewCell.h | ||
// Pods | ||
// | ||
// Created by 张行 on 2018/2/6. | ||
// | ||
// | ||
|
||
#import "ZHCollectionViewBaseModel.h" | ||
|
||
/** | ||
注册 Cell 样式 | ||
*/ | ||
@interface ZHCollectionViewCell<CellType:UICollectionViewCell *> : ZHCollectionViewBaseModel | ||
|
||
/** | ||
Cell 的个数 默认为1 | ||
*/ | ||
@property (nonatomic, assign) NSInteger cellNumber; | ||
/** | ||
配置 Cell的回调 | ||
*/ | ||
@property (nonatomic, copy) void(^configCompletionHandle)(CellType cell, NSIndexPath *indexPath); | ||
/** | ||
点击 Cell 的回调 | ||
*/ | ||
@property (nonatomic, copy) void(^didSelectRowCompletionHandle)(CellType cell, NSIndexPath *indexPath); | ||
|
||
/** | ||
* 为了是支持泛型 | ||
@param configCompletionHandle 设置的Block | ||
*/ | ||
- (void)setConfigCompletionHandle:(void (^)(CellType cell, NSIndexPath * indexPath))configCompletionHandle; | ||
|
||
/** | ||
* 为了支持泛型 | ||
@param didSelectRowCompletionHandle 点击回调的block | ||
*/ | ||
- (void)setDidSelectRowCompletionHandle:(void (^)(CellType cell, NSIndexPath * indexPath))didSelectRowCompletionHandle; | ||
|
||
/** | ||
点击所在的 Cell 的执行方法 | ||
@param cell 点击的 Cell | ||
@param indexPath 点击 cell 所在的索引 | ||
*/ | ||
- (void)didSelectRowAtWithCell:(CellType)cell | ||
indexPath:(NSIndexPath *)indexPath; | ||
|
||
/** | ||
配置 Cell 的执行方法 | ||
@param cell 配置的 Cell | ||
@param indexPath 配置 Cell 所在的索引 | ||
*/ | ||
- (void)configCellWithCell:(CellType)cell | ||
indexPath:(NSIndexPath *)indexPath; | ||
|
||
/** | ||
一个方法配置所有的参数 | ||
@param cellNumber cell 的数量 | ||
@param identifier 标识符 | ||
@param anyClass cell 的类名 | ||
@param height 高度 | ||
@param configCompletionHandle 配置 cell | ||
@param didSelectRowCompletionHandle 点击 cell 方法 | ||
*/ | ||
- (void)configurationCellWithCellNumber:(NSUInteger)cellNumber | ||
identifier:(NSString *)identifier | ||
anyClass:(Class)anyClass | ||
height:(CGFloat)height | ||
configCompletionHandle:(void(^)(CellType cell, NSIndexPath *indexPath))configCompletionHandle | ||
didSelectRowCompletionHandle:(void(^)(CellType cell, NSIndexPath *indexPath))didSelectRowCompletionHandle; | ||
|
||
@end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// | ||
// ZHCollectionViewCell.m | ||
// Pods | ||
// | ||
// Created by 张行 on 2018/2/6. | ||
// | ||
// | ||
|
||
#import "ZHCollectionViewCell.h" | ||
|
||
@implementation ZHCollectionViewCell { | ||
} | ||
|
||
- (instancetype)init { | ||
if (self = [super init]) { | ||
_cellNumber = 1; | ||
} | ||
return self; | ||
} | ||
|
||
- (void)setConfigCompletionHandle:(void (^)(UICollectionViewCell *, NSIndexPath *))configCompletionHandle { | ||
_configCompletionHandle = configCompletionHandle; | ||
} | ||
|
||
- (void)setDidSelectRowCompletionHandle:(void (^)(UICollectionViewCell *, NSIndexPath *))didSelectRowCompletionHandle { | ||
_didSelectRowCompletionHandle = didSelectRowCompletionHandle; | ||
} | ||
|
||
- (void)didSelectRowAtWithCell:(UICollectionViewCell *)cell | ||
indexPath:(NSIndexPath *)indexPath { | ||
if (!self.didSelectRowCompletionHandle) { | ||
return; | ||
} | ||
self.didSelectRowCompletionHandle(cell,indexPath); | ||
} | ||
|
||
- (void)configCellWithCell:(UICollectionViewCell *)cell | ||
indexPath:(NSIndexPath *)indexPath { | ||
if (!self.configCompletionHandle) { | ||
return; | ||
} | ||
self.configCompletionHandle(cell,indexPath); | ||
} | ||
|
||
- (void)configurationCellWithCellNumber:(NSUInteger)cellNumber | ||
identifier:(NSString *)identifier | ||
anyClass:(Class)anyClass | ||
height:(CGFloat)height | ||
configCompletionHandle:(void (^)(UICollectionViewCell *, NSIndexPath *))configCompletionHandle | ||
didSelectRowCompletionHandle:(void (^)(UICollectionViewCell *, NSIndexPath *))didSelectRowCompletionHandle { | ||
self.cellNumber = cellNumber; | ||
self.identifier = identifier; | ||
self.anyClass = anyClass; | ||
self.height = height; | ||
self.configCompletionHandle = configCompletionHandle; | ||
self.didSelectRowCompletionHandle = didSelectRowCompletionHandle; | ||
} | ||
|
||
@end | ||
|
Oops, something went wrong.