@@ -199,7 +199,7 @@ - (BOOL)isSectionOpen:(NSInteger)section {
199
199
200
200
- (void )toggleSection : (NSInteger )section {
201
201
FZAccordionTableViewHeaderView *headerView = (FZAccordionTableViewHeaderView *)[self headerViewForSection: section];
202
- [self tappedHeaderView : headerView];
202
+ [self toggleSection: section withHeaderView : headerView];
203
203
}
204
204
205
205
- (NSInteger )sectionForHeaderView : (UITableViewHeaderFooterView *)headerView {
@@ -259,11 +259,46 @@ - (void)tappedHeaderView:(FZAccordionTableViewHeaderView *)sectionHeaderView {
259
259
NSParameterAssert (sectionHeaderView);
260
260
261
261
NSInteger section = [self sectionForHeaderView: sectionHeaderView];
262
+ [self toggleSection: section withHeaderView: sectionHeaderView];
263
+ }
264
+
265
+ - (void )closeAllSectionsExcept : (NSInteger )section {
266
+ // Get all of the sections that we need to close
267
+ NSMutableSet *sectionsToClose = [[NSMutableSet alloc ] init ];
268
+ for (NSInteger i = 0 ; i < self.numberOfSections ; i++) {
269
+ FZAccordionTableViewSectionInfo *sectionInfo = self.sectionInfos [i];
270
+ if (section != i && sectionInfo.isOpen ) {
271
+ [sectionsToClose addObject: @(i)];
272
+ }
273
+ }
262
274
275
+ // Close the found sections
276
+ for (NSNumber *sectionToClose in sectionsToClose) {
277
+
278
+ // Change animations based off which sections are closed
279
+ UITableViewRowAnimation closeAnimation = UITableViewRowAnimationTop;
280
+ if (section < sectionToClose.integerValue ) {
281
+ closeAnimation = UITableViewRowAnimationBottom;
282
+ }
283
+ if (self.enableAnimationFix ) {
284
+ if (!self.allowsMultipleSelection &&
285
+ (sectionToClose.integerValue == self.sectionInfos .count - 1 ||
286
+ sectionToClose.integerValue == self.sectionInfos .count - 2 )) {
287
+ closeAnimation = UITableViewRowAnimationFade;
288
+ }
289
+ }
290
+
291
+ [self closeSection: sectionToClose.integerValue withHeaderView: (FZAccordionTableViewHeaderView *)[self headerViewForSection: sectionToClose.integerValue] rowAnimation: closeAnimation];
292
+ }
293
+ }
294
+
295
+ #pragma mark - Open / Closing
296
+
297
+ - (void )toggleSection : (NSInteger )section withHeaderView : (nullable FZAccordionTableViewHeaderView *)sectionHeaderView {
263
298
if (![self canInteractWithHeaderAtSection: section]) {
264
299
return ;
265
300
}
266
-
301
+
267
302
// Keep at least one section open
268
303
if (self.keepOneSectionOpen ) {
269
304
NSInteger countOfOpenSections = 0 ;
@@ -273,7 +308,7 @@ - (void)tappedHeaderView:(FZAccordionTableViewHeaderView *)sectionHeaderView {
273
308
countOfOpenSections++;
274
309
}
275
310
}
276
-
311
+
277
312
if (countOfOpenSections == 1 && [self isSectionOpen: section]) {
278
313
return ;
279
314
}
@@ -299,39 +334,7 @@ - (void)tappedHeaderView:(FZAccordionTableViewHeaderView *)sectionHeaderView {
299
334
[self endUpdates ];
300
335
}
301
336
302
- - (void )closeAllSectionsExcept : (NSInteger )section {
303
- // Get all of the sections that we need to close
304
- NSMutableSet *sectionsToClose = [[NSMutableSet alloc ] init ];
305
- for (NSInteger i = 0 ; i < self.numberOfSections ; i++) {
306
- FZAccordionTableViewSectionInfo *sectionInfo = self.sectionInfos [i];
307
- if (section != i && sectionInfo.isOpen ) {
308
- [sectionsToClose addObject: @(i)];
309
- }
310
- }
311
-
312
- // Close the found sections
313
- for (NSNumber *sectionToClose in sectionsToClose) {
314
-
315
- // Change animations based off which sections are closed
316
- UITableViewRowAnimation closeAnimation = UITableViewRowAnimationTop;
317
- if (section < sectionToClose.integerValue ) {
318
- closeAnimation = UITableViewRowAnimationBottom;
319
- }
320
- if (self.enableAnimationFix ) {
321
- if (!self.allowsMultipleSelection &&
322
- (sectionToClose.integerValue == self.sectionInfos .count - 1 ||
323
- sectionToClose.integerValue == self.sectionInfos .count - 2 )) {
324
- closeAnimation = UITableViewRowAnimationFade;
325
- }
326
- }
327
-
328
- [self closeSection: sectionToClose.integerValue withHeaderView: (FZAccordionTableViewHeaderView *)[self headerViewForSection: sectionToClose.integerValue] rowAnimation: closeAnimation];
329
- }
330
- }
331
-
332
- #pragma mark - Open / Closing
333
-
334
- - (void )openSection : (NSInteger )section withHeaderView : (FZAccordionTableViewHeaderView *)sectionHeaderView {
337
+ - (void )openSection : (NSInteger )section withHeaderView : (nullable FZAccordionTableViewHeaderView *)sectionHeaderView {
335
338
if (![self canInteractWithHeaderAtSection: section]) {
336
339
return ;
337
340
}
@@ -370,11 +373,11 @@ - (void)openSection:(NSInteger)section withHeaderView:(FZAccordionTableViewHeade
370
373
[self endUpdates ];
371
374
}
372
375
373
- - (void )closeSection : (NSInteger )section withHeaderView : (FZAccordionTableViewHeaderView *)sectionHeaderView {
376
+ - (void )closeSection : (NSInteger )section withHeaderView : (nullable FZAccordionTableViewHeaderView *)sectionHeaderView {
374
377
[self closeSection: section withHeaderView: sectionHeaderView rowAnimation: UITableViewRowAnimationTop];
375
378
}
376
379
377
- - (void )closeSection : (NSInteger )section withHeaderView : (FZAccordionTableViewHeaderView *)sectionHeaderView rowAnimation : (UITableViewRowAnimation)rowAnimation {
380
+ - (void )closeSection : (NSInteger )section withHeaderView : (nullable FZAccordionTableViewHeaderView *)sectionHeaderView rowAnimation : (UITableViewRowAnimation)rowAnimation {
378
381
if (![self canInteractWithHeaderAtSection: section]) {
379
382
return ;
380
383
}
0 commit comments