Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
805 | - | 1 | // |
2 | // PSToggleSwitchSpecifier.m |
||
3 | // InAppSettingsTestApp |
||
4 | // |
||
5 | // Created by David Keegan on 11/21/09. |
||
6 | // Copyright 2009 InScopeApps{+}. All rights reserved. |
||
7 | // |
||
8 | |||
9 | #import "InAppSettingsPSToggleSwitchSpecifierCell.h" |
||
10 | #import "InAppSettingsConstants.h" |
||
11 | |||
12 | @implementation InAppSettingsPSToggleSwitchSpecifierCell |
||
13 | |||
14 | @synthesize valueSwitch; |
||
15 | |||
16 | // The value associated with the preference when the toggle switch |
||
17 | // is in the ON position. The value type for this key can be any |
||
18 | // scalar type, including Boolean, String, Number, Date, or Data. |
||
19 | // If this key is not present, the default value type is a Boolean. |
||
20 | |||
21 | - (BOOL)getBool{ |
||
22 | id value = [self.setting getValue]; |
||
23 | id trueValue = [self.setting valueForKey:@"TrueValue"]; |
||
24 | id falseValue = [self.setting valueForKey:@"FalseValue"]; |
||
25 | |||
26 | if([value isEqual:trueValue]){ |
||
27 | return YES; |
||
28 | } |
||
29 | |||
30 | if([value isEqual:falseValue]){ |
||
31 | return NO; |
||
32 | } |
||
33 | |||
34 | //if there is no true or false values the value has to be a bool |
||
35 | return [value boolValue]; |
||
36 | } |
||
37 | |||
38 | - (void)setBool:(BOOL)newValue{ |
||
39 | id value = [NSNumber numberWithBool:newValue]; |
||
40 | if(newValue){ |
||
41 | id trueValue = [self.setting valueForKey:@"TrueValue"]; |
||
42 | if(trueValue){ |
||
43 | value = trueValue; |
||
44 | } |
||
45 | } |
||
46 | else{ |
||
47 | id falseValue = [self.setting valueForKey:@"FalseValue"]; |
||
48 | if(falseValue){ |
||
49 | value = falseValue; |
||
50 | } |
||
51 | } |
||
52 | [self.setting setValue:value]; |
||
53 | } |
||
54 | |||
55 | - (void)switchAction{ |
||
56 | [self setBool:[self.valueSwitch isOn]]; |
||
57 | } |
||
58 | |||
59 | - (void)setUIValues{ |
||
60 | [super setUIValues]; |
||
61 | |||
62 | [self setTitle]; |
||
63 | self.valueSwitch.on = [self getBool]; |
||
64 | } |
||
65 | |||
66 | - (void)setupCell{ |
||
67 | [super setupCell]; |
||
68 | |||
69 | //create the switch |
||
70 | self.valueSwitch = [[UISwitch alloc] initWithFrame:CGRectZero]; |
||
71 | CGRect valueSwitchFrame = self.valueSwitch.frame; |
||
72 | valueSwitchFrame.origin.y = (CGFloat)round((self.contentView.frame.size.height*0.5f)-(valueSwitchFrame.size.height*0.5f))-InAppSettingsOffsetY; |
||
73 | valueSwitchFrame.origin.x = (CGFloat)round((InAppSettingsScreenWidth-(InAppSettingsTotalTablePadding+InAppSettingsCellPadding))-valueSwitchFrame.size.width); |
||
74 | self.valueSwitch.frame = valueSwitchFrame; |
||
75 | [self.valueSwitch addTarget:self action:@selector(switchAction) forControlEvents:UIControlEventValueChanged]; |
||
76 | [self.contentView addSubview:self.valueSwitch]; |
||
77 | } |
||
78 | |||
79 | - (void)dealloc{ |
||
80 | [valueSwitch release]; |
||
81 | [super dealloc]; |
||
82 | } |
||
83 | |||
84 | @end |