@@ -67,6 +67,9 @@ - (void)singleInit {
67
67
}
68
68
69
69
- (void )touchedHeaderView : (UITapGestureRecognizer *)recognizer {
70
+
71
+
72
+
70
73
[self .delegate headerView: self didSelectHeaderInSection: self .section];
71
74
}
72
75
@@ -162,7 +165,7 @@ - (void)toggleSection:(NSInteger)section {
162
165
[self headerView: headerView didSelectHeaderInSection: section];
163
166
}
164
167
165
- #pragma mark - Handle message forwarding -
168
+ #pragma mark - UITableView Overrides -
166
169
167
170
- (void )setDelegate : (id <UITableViewDelegate, FZAccordionTableViewDelegate>)delegate {
168
171
self.subclassDelegate = delegate;
@@ -174,6 +177,35 @@ - (void)setDataSource:(id<UITableViewDataSource>)dataSource {
174
177
super.dataSource = self;
175
178
}
176
179
180
+ - (void )deleteSections : (NSIndexSet *)sections withRowAnimation : (UITableViewRowAnimation)animation {
181
+
182
+ // Loop:
183
+ // [self headerViewForSection:section];
184
+ // stop when its past the possible table view bounds.
185
+ // update each of the sections by 1.
186
+
187
+
188
+ // You can also utilize: viewForHeaderInSection
189
+ // Save the lowest possible section that was called for viewForHeaderInSection???
190
+ //
191
+ // [sections enumerateIndexesWithOptions:NSEnumerationReverse usingBlock:^(NSUInteger idx, BOOL * _Nonnull stop) {
192
+ //
193
+ // }];
194
+ //
195
+ // for (int i = sections.firstIndex; i < self.numberOfSections; i++) {
196
+ // FZAccordionTableViewHeaderView *headerView = [self tableView:self viewForHeaderInSection:i];
197
+ // headerView.section--;
198
+ // }
199
+
200
+ [sections enumerateIndexesUsingBlock: ^(NSUInteger index, BOOL * _Nonnull stop) {
201
+ self.numOfRowsForSection [@(index)] = nil ;
202
+ [self .openedSections removeObject: @(index)];
203
+ }];
204
+ [super deleteSections: sections withRowAnimation: animation];
205
+ }
206
+
207
+ #pragma mark - Forwarding handling -
208
+
177
209
- (id )forwardingTargetForSelector : (SEL )aSelector {
178
210
if ([self .subclassDataSource respondsToSelector: aSelector]) {
179
211
return self.subclassDataSource ;
@@ -213,8 +245,41 @@ - (void)setInitialOpenSections:(NSSet *)initialOpenedSections {
213
245
214
246
#pragma mark - FZAccordionTableViewHeaderViewDelegate -
215
247
248
+
249
+
250
+ - (NSInteger )sectionForHeaderView : (UITableViewHeaderFooterView *)headerView {
251
+
252
+ NSInteger section = NSNotFound ;
253
+ NSInteger min = 0 ;
254
+ NSInteger max = self.numberOfSections ;
255
+
256
+ CGRect headerViewFrame = headerView.frame ;
257
+ CGRect compareHeaderViewFrame;
258
+
259
+ while (min <= max) {
260
+ NSInteger mid = (min+max)/2 ;
261
+ compareHeaderViewFrame = [self rectForHeaderInSection: mid];
262
+ if (CGRectEqualToRect (headerViewFrame, compareHeaderViewFrame)) {
263
+ section = mid;
264
+ break ;
265
+ }
266
+ else if (headerViewFrame.origin .y > compareHeaderViewFrame.origin .y ) {
267
+ min = mid+1 ;
268
+ }
269
+ else {
270
+ max = mid-1 ;
271
+ }
272
+ }
273
+
274
+ return section;
275
+ }
276
+
277
+
278
+
216
279
- (void )headerView : (FZAccordionTableViewHeaderView *)sectionHeaderView didSelectHeaderInSection : (NSInteger )section {
217
280
281
+ section = [self sectionForHeaderView: sectionHeaderView];
282
+
218
283
// Do not interact with sections that are always opened
219
284
if ([self isAlwaysOpenedSection: section]) {
220
285
return ;
0 commit comments