Skip to content

Commit 7498d57

Browse files
committed
更新返回的 IndexPath 替换成局部的索引
1 parent da14251 commit 7498d57

14 files changed

Lines changed: 49 additions & 17 deletions

.DS_Store

6 KB
Binary file not shown.

ZHTableViewGroup/.DS_Store

-8 KB
Binary file not shown.

ZHTableViewGroup/Assets/.gitkeep

Whitespace-only changes.

ZHTableViewGroup/Classes/.gitkeep

Whitespace-only changes.

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
}

ZHTableViewGroup/Classes/ZHTableViewBaseModel.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
// Created by 张行 on 2017/3/18.
66
//
77
//
8-
#import <UIKit/UIKit.h>
98

109
@class ZHTableViewBaseModel;
1110

ZHTableViewGroup/Classes/ZHTableViewCell.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
// Created by 张行 on 2017/3/18.
66
//
77
//
8-
#import <UIKit/UIKit.h>
8+
99
#import "ZHTableViewBaseModel.h"
1010

1111
/**

ZHTableViewGroup/Classes/ZHTableViewDataSource.h

Lines changed: 3 additions & 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
#import "ZHTableViewGroup.h"
1111
#import "ZHTableViewGroup.h"
1212
#import "ZHTableViewCell.h"
@@ -144,4 +144,6 @@ typedef CGFloat (^ZHTableViewDataSourceCustomHeightCompletionHandle)(ZHTableView
144144
*/
145145
- (void)clearData;
146146

147+
+ (NSIndexPath *)indexPathWithDataSource:(ZHTableViewDataSource *)dataSource indexPath:(NSIndexPath *)indexPath;
148+
147149
@end

ZHTableViewGroup/Classes/ZHTableViewDataSource.m

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,11 @@ + (CGFloat)heightForRowAtDataSource:(ZHTableViewDataSource *)dataSource
8484
if (!cell) {
8585
return 0;
8686
}
87+
UITableViewCell *automaticHeightCell = [self cellForRowAtWithDataSource:dataSource indexPath:indexPath];
88+
CGFloat automaticHeight = [automaticHeightCell sizeThatFits:CGSizeMake([UIScreen mainScreen].bounds.size.width, CGFLOAT_MAX)].height;
89+
if (cell.height == NSNotFound && automaticHeight != CGFLOAT_MAX) {
90+
cell.height = automaticHeight;
91+
}
8792
return [self heightWithCustomHandle:cell.height customCompletionHandle:customHeightCompletionHandle baseModel:cell];
8893
}
8994

@@ -94,7 +99,8 @@ + (void)didSelectRowAtWithDataSource:(ZHTableViewDataSource *)dataSource
9499
return;
95100
}
96101
UITableViewCell *cell = [self cellForRowAtWithDataSource:dataSource indexPath:indexPath];
97-
[tableViewCell didSelectRowAtWithCell:cell indexPath:indexPath];
102+
ZHTableViewGroup *group = [self groupForSectionWithDataSource:dataSource section:indexPath.section];
103+
[tableViewCell didSelectRowAtWithCell:cell indexPath:[group indexPathWithCell:tableViewCell indexPath:indexPath]];
98104
}
99105

100106
+ (CGFloat)heightForHeaderInSectionWithDataSource:(ZHTableViewDataSource *)dataSource
@@ -139,10 +145,13 @@ + (CGFloat)heightForHeaderFooterInSectionWithDataSource:(ZHTableViewDataSource *
139145
}
140146
NSInteger height = 0;
141147
ZHTableViewBaseModel *baseModel;
148+
UITableViewHeaderFooterView *headFooter = [self viewHeaderFooterInSectionWithDtaSource:dataSource section:section style:style];
149+
CGFloat automaticHeight = [headFooter sizeThatFits:CGSizeMake([UIScreen mainScreen].bounds.size.width, CGFLOAT_MAX)].height;
142150
switch (style) {
143151
case ZHTableViewHeaderFooterStyleHeader: {
144152
height = group.header.height;
145153
baseModel = group.header;
154+
146155
}
147156
break;
148157
case ZHTableViewHeaderFooterStyleFooter: {
@@ -151,19 +160,22 @@ + (CGFloat)heightForHeaderFooterInSectionWithDataSource:(ZHTableViewDataSource *
151160
}
152161
break;
153162
}
163+
if (height == NSNotFound && automaticHeight != CGFLOAT_MAX) {
164+
height = automaticHeight;
165+
}
154166
return [self heightWithCustomHandle:height customCompletionHandle:customHeightCompletionHandle baseModel:baseModel];
155167
}
156168

157169
+ (CGFloat)heightWithCustomHandle:(CGFloat)height
158170
customCompletionHandle:(ZHTableViewDataSourceCustomHeightCompletionHandle)customCompletionHandle
159171
baseModel:(ZHTableViewBaseModel *)baseModel {
160-
if (height == NSNotFound) {
161-
if (customCompletionHandle) {
162-
return customCompletionHandle(baseModel);
163-
}
164-
return 0;
165-
}
166-
return height;
172+
if (customCompletionHandle) {
173+
return customCompletionHandle(baseModel);
174+
}
175+
if (height != 0) {
176+
return height;
177+
}
178+
return 44;
167179
}
168180

169181

@@ -187,6 +199,12 @@ + (ZHTableViewCell *)cellForIndexPath:(ZHTableViewDataSource *)dataSource
187199
return [group tableViewCellForIndexPath:indexPath];
188200
}
189201

202+
+ (NSIndexPath *)indexPathWithDataSource:(ZHTableViewDataSource *)dataSource indexPath:(NSIndexPath *)indexPath {
203+
ZHTableViewGroup *group = [self groupForSectionWithDataSource:dataSource section:indexPath.section];
204+
ZHTableViewCell *tableViewCell = [self cellForIndexPath:dataSource indexPath:indexPath];
205+
return [group indexPathWithCell:tableViewCell indexPath:indexPath];
206+
}
207+
190208
- (void)registerClasss {
191209
for (ZHTableViewGroup *group in self.groups) {
192210
[group registerHeaderFooterCellWithTableView:self.tableView];

0 commit comments

Comments
 (0)