11 #import "EditorSelectionController.h"
12 #import "ConnectionParams.h"
13 #import "OrderedDictionary.h"
15 @interface EditorSelectionController (Private)
22 entries:(NSArray *)entries
23 selections:(NSArray *)selections
25 self = [
super initWithStyle:UITableViewStyleGrouped];
28 _params = [params retain];
29 _entries = [entries retain];
30 _selections = [selections retain];
33 _cur_selections = [[NSMutableArray alloc] initWithCapacity:[_entries count]];
34 for (
int i = 0; i < [entries count]; ++i)
36 NSString *entry = [entries objectAtIndex:i];
37 if ([_params hasValueForKeyPath:entry])
40 indexForValue:[NSNumber numberWithInt:[_params intForKeyPath:entry]]];
41 [_cur_selections addObject:[NSNumber numberWithInt:(idx != NSNotFound ? idx : 0)]];
44 [_cur_selections addObject:[NSNumber numberWithInt:0]];
50 - (void)didReceiveMemoryWarning
53 [
super didReceiveMemoryWarning];
56 [_params autorelease];
57 [_entries autorelease];
58 [_selections autorelease];
59 [_cur_selections autorelease];
62 #pragma mark - View lifecycle
64 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
70 #pragma mark - Table view data source
72 - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
75 return [_entries count];
78 - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
81 return [[
self selectionForIndex:section] count];
84 - (UITableViewCell *)tableView:(UITableView *)tableView
85 cellForRowAtIndexPath:(NSIndexPath *)indexPath
87 UITableViewCell *cell = [
self tableViewCellFromIdentifier:TableCellIdentifierMultiChoice];
93 [[cell textLabel] setText:[selection keyAtIndex:[indexPath row]]];
96 if ([indexPath row] == [[_cur_selections objectAtIndex:[indexPath section]] intValue])
97 [cell setAccessoryType:UITableViewCellAccessoryCheckmark];
99 [cell setAccessoryType:UITableViewCellAccessoryNone];
104 #pragma mark - Table view delegate
106 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
109 int cur_selection = [[_cur_selections objectAtIndex:[indexPath section]] intValue];
110 if ([indexPath row] != cur_selection)
112 [tableView deselectRowAtIndexPath:indexPath animated:NO];
114 NSIndexPath *oldIndexPath = [NSIndexPath indexPathForRow:cur_selection
115 inSection:[indexPath section]];
118 UITableViewCell *old_sel_cell = [tableView cellForRowAtIndexPath:oldIndexPath];
119 old_sel_cell.accessoryType = UITableViewCellAccessoryNone;
122 UITableViewCell *new_sel_cell = [tableView cellForRowAtIndexPath:indexPath];
123 new_sel_cell.accessoryType = UITableViewCellAccessoryCheckmark;
127 int sel_value = [[dict valueForKey:[dict keyAtIndex:[indexPath row]]] intValue];
130 [_cur_selections replaceObjectAtIndex:[indexPath section]
131 withObject:[NSNumber numberWithInt:[indexPath row]]];
132 [_params setInt:sel_value forKeyPath:[_entries objectAtIndex:[indexPath section]]];
136 #pragma mark - Convenience functions