Skip to content

Commit

Permalink
Merge pull request #3 from josercc/developer-josercc
Browse files Browse the repository at this point in the history
Developer josercc
  • Loading branch information
josercc authored Mar 27, 2018
2 parents d858d42 + 116aead commit 7e6037d
Show file tree
Hide file tree
Showing 28 changed files with 1,111 additions and 31 deletions.
Binary file modified .DS_Store
Binary file not shown.
65 changes: 55 additions & 10 deletions Example/Pods/Pods.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions Example/ZHTableViewGroup/ZHViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,13 @@ - (void)registerOtherCell:(ZHTableViewCell *)cell title:(NSString *)title detail
cell.textLabel.text = title;
cell.detailTextLabel.text = detailTitle;
cell.accessoryType = accessoryType;
cell.accessoryView = [[UISwitch alloc] initWithFrame:CGRectZero];
}];

[cell setDidSelectRowCompletionHandle:^(UITableViewCell *cell, NSIndexPath *indexPath) {
UISwitch *switch1 = cell.accessoryView;
[switch1 setOn:!switch1.on animated:YES];
}];
}

- (void)registerBlankCell:(ZHTableViewCell *)cell {
Expand Down
Binary file removed ZHTableViewGroup/.DS_Store
Binary file not shown.
Empty file removed ZHTableViewGroup/Assets/.gitkeep
Empty file.
Empty file removed ZHTableViewGroup/Classes/.gitkeep
Empty file.
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

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

Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
//
//

#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>

typedef NS_ENUM(NSUInteger, ZHTableViewCustomHeightType) {
ZHTableViewCustomHeightTypeCell,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ - (ZHTableViewDataSourceCustomHeightCompletionHandle)completionHandleWithTableVi
if (!model.customHeightCompletionHandle) {
return model.height;
}
return model.customHeightCompletionHandle(tableView,indexPath,model);
return model.customHeightCompletionHandle(tableView,[ZHTableViewDataSource indexPathWithDataSource:_dataSource indexPath:indexPath],model);
};
return completionHandle;
}
Expand Down
36 changes: 36 additions & 0 deletions ZHTableViewGroup/Classes/ZHCollectionViewBaseModel.h
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

21 changes: 21 additions & 0 deletions ZHTableViewGroup/Classes/ZHCollectionViewBaseModel.m
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

80 changes: 80 additions & 0 deletions ZHTableViewGroup/Classes/ZHCollectionViewCell.h
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

60 changes: 60 additions & 0 deletions ZHTableViewGroup/Classes/ZHCollectionViewCell.m
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

Loading

0 comments on commit 7e6037d

Please sign in to comment.