Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
805 | - | 1 | // |
2 | // PSMultiValueSpecifierTable.m |
||
3 | // InAppSettings |
||
4 | // |
||
5 | // Created by David Keegan on 11/3/09. |
||
6 | // Copyright 2009 InScopeApps{+}. All rights reserved. |
||
7 | // |
||
8 | |||
9 | #import "InAppSettings.h" |
||
10 | #import "InAppSettingsPSMultiValueSpecifierTable.h" |
||
11 | #import "InAppSettingsConstants.h" |
||
12 | |||
13 | @implementation InAppSettingsPSMultiValueSpecifierTable |
||
14 | |||
15 | @synthesize setting; |
||
16 | |||
17 | - (id) initWithStyle:(UITableViewStyle)style { |
||
18 | return [super initWithStyle:UITableViewStyleGrouped]; |
||
19 | } |
||
20 | |||
21 | - (id) initWithSetting:(InAppSettingsSpecifier *)inputSetting { |
||
22 | self = [super init]; |
||
23 | if (self != nil) { |
||
24 | self.setting = inputSetting; |
||
25 | } |
||
26 | return self; |
||
27 | } |
||
28 | |||
29 | - (void) viewDidLoad { |
||
30 | [super viewDidLoad]; |
||
31 | |||
32 | self.title = [self.setting localizedTitle]; |
||
33 | } |
||
34 | |||
35 | - (void) dealloc { |
||
36 | [setting release]; |
||
37 | [super dealloc]; |
||
38 | } |
||
39 | |||
40 | #pragma mark Value |
||
41 | |||
42 | - (id) getValue { |
||
43 | |||
44 | id value; |
||
45 | |||
46 | if ( self.setting.dataSource != nil ) |
||
47 | value = [self.setting.dataSource objectForKey:[self.setting getKey]]; |
||
48 | else |
||
49 | value = [[NSUserDefaults standardUserDefaults] valueForKey:[self.setting getKey]]; |
||
50 | |||
51 | if (value == nil) { |
||
52 | value = [self.setting valueForKey:InAppSettingsSpecifierDefaultValue]; |
||
53 | } |
||
54 | return value; |
||
55 | } |
||
56 | |||
57 | - (void) setValue:(id)newValue { |
||
58 | if ( self.setting.dataSource != nil ) |
||
59 | [self.setting.dataSource setObject:newValue forKey:[self.setting getKey]]; |
||
60 | else |
||
61 | [[NSUserDefaults standardUserDefaults] setObject:newValue forKey:[self.setting getKey]]; |
||
62 | } |
||
63 | |||
64 | #pragma mark Table view methods |
||
65 | |||
66 | - (NSInteger) numberOfSectionsInTableView:(UITableView *)tableView { |
||
67 | return 1; |
||
68 | } |
||
69 | |||
70 | - (NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { |
||
71 | return [[self.setting valueForKey:InAppSettingsSpecifierValues] count]; |
||
72 | } |
||
73 | |||
74 | - (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { |
||
75 | static NSString * CellIdentifier = @"PSMultiValueSpecifierTableCell"; |
||
76 | |||
77 | UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; |
||
78 | |||
79 | if (cell == nil) { |
||
80 | #if InAppSettingsUseNewCells |
||
81 | cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; |
||
82 | #else |
||
83 | cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease]; |
||
84 | #endif |
||
85 | } |
||
86 | |||
87 | NSString * cellTitle = InAppSettingsLocalize([[self.setting valueForKey:InAppSettingsSpecifierTitles] objectAtIndex:indexPath.row], self.setting.stringsTable); |
||
88 | id cellValue = [[self.setting valueForKey:InAppSettingsSpecifierValues] objectAtIndex:indexPath.row]; |
||
89 | #if InAppSettingsUseNewCells |
||
90 | cell.textLabel.text = cellTitle; |
||
91 | #else |
||
92 | cell.text = cellTitle; |
||
93 | #endif |
||
94 | if ([cellValue isEqual:[self getValue]]) { |
||
95 | cell.accessoryType = UITableViewCellAccessoryCheckmark; |
||
96 | #if InAppSettingsUseNewCells |
||
97 | cell.textLabel.textColor = InAppSettingsBlue; |
||
98 | #else |
||
99 | cell.textColor = InAppSettingsBlue; |
||
100 | #endif |
||
101 | } else { |
||
102 | cell.accessoryType = UITableViewCellAccessoryNone; |
||
103 | #if InAppSettingsUseNewCells |
||
104 | cell.textLabel.textColor = [UIColor blackColor]; |
||
105 | #else |
||
106 | cell.textColor = [UIColor blackColor]; |
||
107 | #endif |
||
108 | } |
||
109 | |||
110 | return cell; |
||
111 | } |
||
112 | |||
113 | - (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { |
||
114 | [tableView deselectRowAtIndexPath:[tableView indexPathForSelectedRow] animated:YES]; |
||
115 | } |
||
116 | |||
117 | - (NSIndexPath *) tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath { |
||
118 | id cellValue = [[self.setting valueForKey:InAppSettingsSpecifierValues] objectAtIndex:indexPath.row]; |
||
119 | |||
120 | [self setValue:cellValue]; |
||
121 | [self.tableView reloadData]; |
||
122 | return indexPath; |
||
123 | } |
||
124 | |||
125 | @end |
||
126 |