• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#import "SkOptionListController.h"
2
3@implementation SkOptionListController
4
5@synthesize fOptions, fSelectedIndex, fSelectedCell, fParentCell;
6
7#pragma mark -
8#pragma mark Initialization
9
10- (id)initWithStyle:(UITableViewStyle)style {
11    self = [super initWithStyle:style];
12    if (self) {
13        self.fOptions = [[NSMutableArray alloc] init];
14        self.fSelectedIndex = 0;
15        self.fSelectedCell = nil;
16    }
17    return self;
18}
19
20- (void)addOption:(NSString*)option {
21    [fOptions addObject:option];
22}
23
24- (NSString*)getSelectedOption {
25    return (NSString*)[fOptions objectAtIndex:self.fSelectedIndex];
26}
27
28#pragma mark -
29#pragma mark Table view data source
30
31- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
32    return 1;
33}
34
35- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
36    return [fOptions count];
37}
38
39- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
40
41    static NSString *CellIdentifier = @"Cell";
42
43    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
44    if (cell == nil) {
45        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
46    }
47
48    cell.textLabel.text = [fOptions objectAtIndex:indexPath.row];
49    if (indexPath.row == fSelectedIndex) {
50        cell.accessoryType = UITableViewCellAccessoryCheckmark;
51        self.fSelectedCell = cell;
52    }
53    else
54        cell.accessoryType = UITableViewCellAccessoryNone;
55
56    return cell;
57}
58
59#pragma mark -
60#pragma mark Table view delegate
61
62- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
63    UITableViewCell* cell = [tableView cellForRowAtIndexPath:indexPath];
64    self.fSelectedCell.accessoryType = UITableViewCellAccessoryNone;
65    self.fSelectedCell = cell;
66    cell.accessoryType = UITableViewCellAccessoryCheckmark;
67    self.fParentCell.detailTextLabel.text = cell.textLabel.text;;
68    self.fSelectedIndex = indexPath.row;
69    [self.navigationController popViewControllerAnimated:YES];
70}
71
72- (void)dealloc {
73    self.fOptions = nil;
74    self.fSelectedCell = nil;
75    [super dealloc];
76}
77
78@end
79