@@ -199,7 +199,7 @@ - (BOOL)isSectionOpen:(NSInteger)section {
199199
200200- (void )toggleSection : (NSInteger )section {
201201 FZAccordionTableViewHeaderView *headerView = (FZAccordionTableViewHeaderView *)[self headerViewForSection: section];
202- [self tappedHeaderView : headerView];
202+ [self toggleSection: section withHeaderView : headerView];
203203}
204204
205205- (NSInteger )sectionForHeaderView : (UITableViewHeaderFooterView *)headerView {
@@ -259,11 +259,46 @@ - (void)tappedHeaderView:(FZAccordionTableViewHeaderView *)sectionHeaderView {
259259 NSParameterAssert (sectionHeaderView);
260260
261261 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+ }
262274
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 {
263298 if (![self canInteractWithHeaderAtSection: section]) {
264299 return ;
265300 }
266-
301+
267302 // Keep at least one section open
268303 if (self.keepOneSectionOpen ) {
269304 NSInteger countOfOpenSections = 0 ;
@@ -273,7 +308,7 @@ - (void)tappedHeaderView:(FZAccordionTableViewHeaderView *)sectionHeaderView {
273308 countOfOpenSections++;
274309 }
275310 }
276-
311+
277312 if (countOfOpenSections == 1 && [self isSectionOpen: section]) {
278313 return ;
279314 }
@@ -299,39 +334,7 @@ - (void)tappedHeaderView:(FZAccordionTableViewHeaderView *)sectionHeaderView {
299334 [self endUpdates ];
300335}
301336
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 {
335338 if (![self canInteractWithHeaderAtSection: section]) {
336339 return ;
337340 }
@@ -370,11 +373,11 @@ - (void)openSection:(NSInteger)section withHeaderView:(FZAccordionTableViewHeade
370373 [self endUpdates ];
371374}
372375
373- - (void )closeSection : (NSInteger )section withHeaderView : (FZAccordionTableViewHeaderView *)sectionHeaderView {
376+ - (void )closeSection : (NSInteger )section withHeaderView : (nullable FZAccordionTableViewHeaderView *)sectionHeaderView {
374377 [self closeSection: section withHeaderView: sectionHeaderView rowAnimation: UITableViewRowAnimationTop];
375378}
376379
377- - (void )closeSection : (NSInteger )section withHeaderView : (FZAccordionTableViewHeaderView *)sectionHeaderView rowAnimation : (UITableViewRowAnimation)rowAnimation {
380+ - (void )closeSection : (NSInteger )section withHeaderView : (nullable FZAccordionTableViewHeaderView *)sectionHeaderView rowAnimation : (UITableViewRowAnimation)rowAnimation {
378381 if (![self canInteractWithHeaderAtSection: section]) {
379382 return ;
380383 }
0 commit comments