@@ -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