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]]];
42 addObject:[NSNumber numberWithInteger:(idx != NSNotFound ? idx : 0)]];
45 [_cur_selections addObject:[NSNumber numberWithInt:0]];
51- (void)didReceiveMemoryWarning
54 [
super didReceiveMemoryWarning];
57 [_params autorelease];
58 [_entries autorelease];
59 [_selections autorelease];
60 [_cur_selections autorelease];
63#pragma mark - View lifecycle
65- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
71#pragma mark - Table view data source
73- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
76 return [_entries count];
79- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
82 return [[
self selectionForIndex:section] count];
85- (UITableViewCell *)tableView:(UITableView *)tableView
86 cellForRowAtIndexPath:(NSIndexPath *)indexPath
88 UITableViewCell *cell = [
self tableViewCellFromIdentifier:TableCellIdentifierMultiChoice];
94 [[cell textLabel] setText:[selection keyAtIndex:[indexPath row]]];
97 if ([indexPath row] == [[_cur_selections objectAtIndex:[indexPath section]] intValue])
98 [cell setAccessoryType:UITableViewCellAccessoryCheckmark];
100 [cell setAccessoryType:UITableViewCellAccessoryNone];
105#pragma mark - Table view delegate
107- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
110 int cur_selection = [[_cur_selections objectAtIndex:[indexPath section]] intValue];
111 if ([indexPath row] != cur_selection)
113 [tableView deselectRowAtIndexPath:indexPath animated:NO];
115 NSIndexPath *oldIndexPath = [NSIndexPath indexPathForRow:cur_selection
116 inSection:[indexPath section]];
119 UITableViewCell *old_sel_cell = [tableView cellForRowAtIndexPath:oldIndexPath];
120 old_sel_cell.accessoryType = UITableViewCellAccessoryNone;
123 UITableViewCell *new_sel_cell = [tableView cellForRowAtIndexPath:indexPath];
124 new_sel_cell.accessoryType = UITableViewCellAccessoryCheckmark;
128 int sel_value = [[dict valueForKey:[dict keyAtIndex:[indexPath row]]] intValue];
131 [_cur_selections replaceObjectAtIndex:[indexPath section]
132 withObject:[NSNumber numberWithInteger:[indexPath row]]];
133 [_params setInt:sel_value forKeyPath:[_entries objectAtIndex:[indexPath section]]];
137#pragma mark - Convenience functions