Permalink
Browse files

Properly support PSToggleSwitchSpecifier that use TrueValue and False…

…Value
  • Loading branch information...
1 parent bb38391 commit 52e9ca57b7b25b3e0a66d55f988fd756821e8c2f Ortwin Gentz committed Jan 15, 2010
@@ -264,8 +264,22 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
options:nil] objectAtIndex:0];
}
[[cell label] setText:[specifier title]];
- [[cell toggle] setOn:[[NSUserDefaults standardUserDefaults] objectForKey:key] != nil ?
- [[[NSUserDefaults standardUserDefaults] objectForKey:key] boolValue] : [[specifier defaultValue] boolValue]];
+
+ id currentValue = [[NSUserDefaults standardUserDefaults] objectForKey:key];
+ BOOL toggleState;
+ if (currentValue) {
+ if ([currentValue isEqual:[specifier trueValue]]) {
+ toggleState = YES;
+ } else if ([currentValue isEqual:[specifier falseValue]]) {
+ toggleState = NO;
+ } else {
+ toggleState = [currentValue boolValue];
+ }
+ } else {
+ toggleState = [specifier defaultBoolValue];
+ }
+ [[cell toggle] setOn:toggleState];
+
[[cell toggle] addTarget:self action:@selector(toggledValue:) forControlEvents:UIControlEventValueChanged];
[[cell toggle] setKey:key];
return cell;
@@ -37,6 +37,7 @@
- (NSString*)file;
- (id)defaultValue;
- (id)defaultStringValue;
+- (BOOL)defaultBoolValue;
- (id)trueValue;
- (id)falseValue;
- (float)minimumValue;
@@ -108,6 +108,17 @@ - (id)defaultStringValue {
return [[_specifierDict objectForKey:kIASKDefaultValue] description];
}
+- (BOOL)defaultBoolValue {
+ id defaultValue = [self defaultValue];
+ if ([defaultValue isEqual:[self trueValue]]) {
+ return YES;
+ }
+ if ([defaultValue isEqual:[self falseValue]]) {
+ return NO;
+ }
+ return [defaultValue boolValue];
+}
+
- (id)trueValue {
return [_specifierDict objectForKey:kIASKTrueValue];
}

0 comments on commit 52e9ca5

Please sign in to comment.