22 #pragma mark View lifecycle |
22 #pragma mark View lifecycle |
23 -(void) viewDidLoad { |
23 -(void) viewDidLoad { |
24 [super viewDidLoad]; |
24 [super viewDidLoad]; |
25 |
25 |
26 self.flagArray = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:FLAGS_DIRECTORY() error:NULL]; |
26 self.flagArray = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:FLAGS_DIRECTORY() error:NULL]; |
27 |
27 |
28 self.title = NSLocalizedString(@"Set team flag",@""); |
28 self.title = NSLocalizedString(@"Set team flag",@""); |
29 } |
29 } |
30 |
30 |
31 -(void) viewWillAppear:(BOOL)animated { |
31 -(void) viewWillAppear:(BOOL)animated { |
32 [super viewWillAppear:animated]; |
32 [super viewWillAppear:animated]; |
45 return [flagArray count]; |
45 return [flagArray count]; |
46 } |
46 } |
47 |
47 |
48 // Customize the appearance of table view cells. |
48 // Customize the appearance of table view cells. |
49 -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { |
49 -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { |
50 |
50 |
51 static NSString *CellIdentifier = @"Cell"; |
51 static NSString *CellIdentifier = @"Cell"; |
52 |
52 |
53 UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; |
53 UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; |
54 if (cell == nil) { |
54 if (cell == nil) { |
55 cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; |
55 cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; |
56 } |
56 } |
57 |
57 |
58 NSString *flag = [flagArray objectAtIndex:[indexPath row]]; |
58 NSString *flag = [flagArray objectAtIndex:[indexPath row]]; |
59 |
59 |
60 NSString *flagFile = [[NSString alloc] initWithFormat:@"%@/%@", FLAGS_DIRECTORY(), flag]; |
60 NSString *flagFile = [[NSString alloc] initWithFormat:@"%@/%@", FLAGS_DIRECTORY(), flag]; |
61 UIImage *flagSprite = [[UIImage alloc] initWithContentsOfFile:flagFile]; |
61 UIImage *flagSprite = [[UIImage alloc] initWithContentsOfFile:flagFile]; |
62 [flagFile release]; |
62 [flagFile release]; |
63 cell.imageView.image = flagSprite; |
63 cell.imageView.image = flagSprite; |
64 [flagSprite release]; |
64 [flagSprite release]; |
65 |
65 |
66 cell.textLabel.text = [flag stringByDeletingPathExtension]; |
66 cell.textLabel.text = [flag stringByDeletingPathExtension]; |
67 if ([cell.textLabel.text isEqualToString:[self.teamDictionary objectForKey:@"flag"]]) { |
67 if ([cell.textLabel.text isEqualToString:[self.teamDictionary objectForKey:@"flag"]]) { |
68 cell.accessoryType = UITableViewCellAccessoryCheckmark; |
68 cell.accessoryType = UITableViewCellAccessoryCheckmark; |
69 self.lastIndexPath = indexPath; |
69 self.lastIndexPath = indexPath; |
70 } else { |
70 } else { |
71 cell.accessoryType = UITableViewCellAccessoryNone; |
71 cell.accessoryType = UITableViewCellAccessoryNone; |
72 } |
72 } |
73 |
73 |
74 return cell; |
74 return cell; |
75 } |
75 } |
76 |
76 |
77 |
77 |
78 #pragma mark - |
78 #pragma mark - |
79 #pragma mark Table view delegate |
79 #pragma mark Table view delegate |
80 -(void) tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { |
80 -(void) tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { |
81 int newRow = [indexPath row]; |
81 int newRow = [indexPath row]; |
82 int oldRow = (lastIndexPath != nil) ? [lastIndexPath row] : -1; |
82 int oldRow = (lastIndexPath != nil) ? [lastIndexPath row] : -1; |
83 |
83 |
84 if (newRow != oldRow) { |
84 if (newRow != oldRow) { |
85 // if the two selected rows differ update data on the hog dictionary and reload table content |
85 // if the two selected rows differ update data on the hog dictionary and reload table content |
86 [self.teamDictionary setValue:[[flagArray objectAtIndex:newRow] stringByDeletingPathExtension] forKey:@"flag"]; |
86 [self.teamDictionary setValue:[[flagArray objectAtIndex:newRow] stringByDeletingPathExtension] forKey:@"flag"]; |
87 |
87 |
88 // tell our boss to write this new stuff on disk |
88 // tell our boss to write this new stuff on disk |