Skip to content

Commit 7e6037d

Browse files
authored
Merge pull request #3 from josercc/developer-josercc
Developer josercc
2 parents d858d42 + 116aead commit 7e6037d

28 files changed

Lines changed: 1111 additions & 31 deletions

.DS_Store

6 KB
Binary file not shown.

Example/Pods/Pods.xcodeproj/project.pbxproj

Lines changed: 55 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Example/ZHTableViewGroup/ZHViewController.m

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,13 @@ - (void)registerOtherCell:(ZHTableViewCell *)cell title:(NSString *)title detail
110110
cell.textLabel.text = title;
111111
cell.detailTextLabel.text = detailTitle;
112112
cell.accessoryType = accessoryType;
113+
cell.accessoryView = [[UISwitch alloc] initWithFrame:CGRectZero];
113114
}];
114115

116+
[cell setDidSelectRowCompletionHandle:^(UITableViewCell *cell, NSIndexPath *indexPath) {
117+
UISwitch *switch1 = cell.accessoryView;
118+
[switch1 setOn:!switch1.on animated:YES];
119+
}];
115120
}
116121

117122
- (void)registerBlankCell:(ZHTableViewCell *)cell {

ZHTableViewGroup/.DS_Store

-8 KB
Binary file not shown.

ZHTableViewGroup/Assets/.gitkeep

Whitespace-only changes.

ZHTableViewGroup/Classes/.gitkeep

Whitespace-only changes.
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
//
2+
// ZHAutoConfigurationCollectionViewDelegate.h
3+
// Pods
4+
//
5+
// Created by 张行 on 2017/4/20.
6+
//
7+
//
8+
9+
#import <Foundation/Foundation.h>
10+
11+
typedef NS_ENUM(NSUInteger, ZHCollectionViewCustomHeightType) {
12+
ZHCollectionViewCustomHeightTypeCell,
13+
ZHCollectionViewCustomHeightTypeHeader,
14+
ZHCollectionViewCustomHeightTypeFooter
15+
};
16+
17+
@class ZHCollectionViewDataSource;
18+
19+
/**
20+
自动配置 UICollectionView 的数据源和代理
21+
默认实现 UICollectionView 的数据源方法和代理方法如下
22+
*/
23+
@interface ZHAutoConfigurationCollectionViewDelegate : NSObject <UICollectionViewDataSource, UICollectionViewDelegate, UICollectionViewDelegateFlowLayout>
24+
25+
/**
26+
初始化自动配置ZHAutoConfigurationCollectionViewDelegate对象
27+
28+
@param dataSource ZHCollectionViewDataSource
29+
@return ZHAutoConfigurationCollectionViewDelegate
30+
*/
31+
- (instancetype)initWithDataSource:(ZHCollectionViewDataSource *)dataSource;
32+
33+
@end
34+
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
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+

ZHTableViewGroup/Classes/ZHAutoConfigurationTableViewDelegate.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
//
77
//
88

9-
#import <UIKit/UIKit.h>
9+
#import <Foundation/Foundation.h>
1010

1111
typedef NS_ENUM(NSUInteger, ZHTableViewCustomHeightType) {
1212
ZHTableViewCustomHeightTypeCell,

ZHTableViewGroup/Classes/ZHAutoConfigurationTableViewDelegate.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ - (ZHTableViewDataSourceCustomHeightCompletionHandle)completionHandleWithTableVi
2525
if (!model.customHeightCompletionHandle) {
2626
return model.height;
2727
}
28-
return model.customHeightCompletionHandle(tableView,indexPath,model);
28+
return model.customHeightCompletionHandle(tableView,[ZHTableViewDataSource indexPathWithDataSource:_dataSource indexPath:indexPath],model);
2929
};
3030
return completionHandle;
3131
}

0 commit comments

Comments
 (0)