Skip to content

Commit

Permalink
Added allowsEmptySelection property as requested in #11
Browse files Browse the repository at this point in the history
  • Loading branch information
suda committed Jan 25, 2014
1 parent c2230c7 commit c02fb73
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 3 deletions.
1 change: 1 addition & 0 deletions AccordionView.h
Expand Up @@ -46,5 +46,6 @@
@property (nonatomic, strong) NSIndexSet *selectionIndexes;
@property (nonatomic, strong) id <AccordionViewDelegate> delegate;
@property (nonatomic, assign) BOOL startsClosed;
@property (nonatomic, assign) BOOL allowsEmptySelection;

@end
10 changes: 7 additions & 3 deletions AccordionView.m
Expand Up @@ -22,7 +22,7 @@
@implementation AccordionView

@synthesize selectedIndex, isHorizontal, animationDuration, animationCurve;
@synthesize allowsMultipleSelection, selectionIndexes, delegate, startsClosed;
@synthesize allowsMultipleSelection, selectionIndexes, delegate, startsClosed, allowsEmptySelection;

- (id)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
Expand Down Expand Up @@ -51,6 +51,8 @@ - (id)initWithFrame:(CGRect)frame {
self.allowsMultipleSelection = NO;

self.startsClosed = NO;

self.allowsEmptySelection = YES;
}

return self;
Expand Down Expand Up @@ -173,15 +175,17 @@ - (void)touchDown:(id)sender {
if (allowsMultipleSelection) {
NSMutableIndexSet *mis = [selectionIndexes mutableCopy];
if ([selectionIndexes containsIndex:[sender tag]]) {
[mis removeIndex:[sender tag]];
if (self.allowsEmptySelection || [selectionIndexes count] > 1) {
[mis removeIndex:[sender tag]];
}
} else {
[mis addIndex:[sender tag]];
}

[self setSelectionIndexes:mis];
} else {
// If the touched section is already opened, close it.
if ([selectionIndexes firstIndex] == [sender tag]) {
if (([selectionIndexes firstIndex] == [sender tag]) && self.allowsEmptySelection) {
[self setSelectionIndexes:[NSIndexSet indexSet]];
} else {
[self setSelectedIndex:[sender tag]];
Expand Down
@@ -0,0 +1,41 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDESourceControlProjectFavoriteDictionaryKey</key>
<false/>
<key>IDESourceControlProjectIdentifier</key>
<string>81B415EA-2485-4B70-84D9-24F6C2783DDB</string>
<key>IDESourceControlProjectName</key>
<string>test</string>
<key>IDESourceControlProjectOriginsDictionary</key>
<dict>
<key>4FF14784-A0E1-4E60-9D17-1B478CCAEF65</key>
<string>ssh://github.com/appsome/AccordionView.git</string>
</dict>
<key>IDESourceControlProjectPath</key>
<string>Example/test.xcodeproj/project.xcworkspace</string>
<key>IDESourceControlProjectRelativeInstallPathDictionary</key>
<dict>
<key>4FF14784-A0E1-4E60-9D17-1B478CCAEF65</key>
<string>../../..</string>
</dict>
<key>IDESourceControlProjectURL</key>
<string>ssh://github.com/appsome/AccordionView.git</string>
<key>IDESourceControlProjectVersion</key>
<integer>110</integer>
<key>IDESourceControlProjectWCCIdentifier</key>
<string>4FF14784-A0E1-4E60-9D17-1B478CCAEF65</string>
<key>IDESourceControlProjectWCConfigurations</key>
<array>
<dict>
<key>IDESourceControlRepositoryExtensionIdentifierKey</key>
<string>public.vcs.git</string>
<key>IDESourceControlWCCIdentifierKey</key>
<string>4FF14784-A0E1-4E60-9D17-1B478CCAEF65</string>
<key>IDESourceControlWCCName</key>
<string>AccordionView</string>
</dict>
</array>
</dict>
</plist>
3 changes: 3 additions & 0 deletions Example/test/ViewController.m
Expand Up @@ -68,6 +68,9 @@ - (void)viewDidLoad

// Set this if you want to allow multiple selection
[accordion setAllowsMultipleSelection:YES];

// Set this to NO if you want to have at least one open section at all times
[accordion setAllowsEmptySelection:YES];
}

- (void)removeSecondRow {
Expand Down

0 comments on commit c02fb73

Please sign in to comment.