From 4c1df5f24fca9a6240f95b956bf62c9a1d1e6a52 Mon Sep 17 00:00:00 2001 From: Michael Lo Date: Fri, 15 Feb 2013 15:20:28 -0500 Subject: [PATCH] Addedcode that will allow multiple sections to be programmatically closed --- .../GCRetractableSectionController.h | 5 ++++- .../GCRetractableSectionController.m | 8 ++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/GCRetractableSectionController/GCRetractableSectionController.h b/GCRetractableSectionController/GCRetractableSectionController.h index 276e83f..8510dbf 100644 --- a/GCRetractableSectionController/GCRetractableSectionController.h +++ b/GCRetractableSectionController/GCRetractableSectionController.h @@ -8,7 +8,9 @@ #import -@interface GCRetractableSectionController : NSObject +@interface GCRetractableSectionController : NSObject { + NSUInteger activeSection; +} @property (nonatomic, assign, getter = isOpen) BOOL open; @@ -38,6 +40,7 @@ - (void) didSelectCellAtRow:(NSUInteger) row; - (void) didSelectTitleCell; - (void) didSelectContentCellAtRow:(NSUInteger) row; +- (void) didSelectCellAtRow:(NSUInteger)row inSection:(NSUInteger)section; //Reserved for subclasses @property (nonatomic, readonly) UIViewController *viewController; diff --git a/GCRetractableSectionController/GCRetractableSectionController.m b/GCRetractableSectionController/GCRetractableSectionController.m index f10012f..9fab798 100644 --- a/GCRetractableSectionController/GCRetractableSectionController.m +++ b/GCRetractableSectionController/GCRetractableSectionController.m @@ -151,12 +151,20 @@ - (void) didSelectCellAtRow:(NSUInteger)row { else [self didSelectContentCellAtRow:row - 1]; } +- (void) didSelectCellAtRow:(NSUInteger)row inSection:(NSUInteger)section { + activeSection = section; + [self didSelectCellAtRow:row]; +} + - (void) didSelectTitleCell { self.open = !self.open; if (self.contentNumberOfRow != 0) [self setAccessoryViewOnCell:[self.tableView cellForRowAtIndexPath:[self.tableView indexPathForSelectedRow]]]; NSIndexPath* indexPath = [self.tableView indexPathForSelectedRow]; NSUInteger section = indexPath.section; + if (indexPath == nil) { + section = activeSection; + } NSUInteger contentCount = self.contentNumberOfRow; [self.tableView beginUpdates];