author | smaxx |
Thu, 02 Sep 2010 19:21:41 +0200 | |
changeset 3811 | 967363197f01 |
parent 3697 | d5b30d6373fc |
child 3829 | 81db3c85784b |
permissions | -rw-r--r-- |
3547 | 1 |
// |
2 |
// FlagsViewController.m |
|
3 |
// HedgewarsMobile |
|
4 |
// |
|
5 |
// Created by Vittorio on 08/04/10. |
|
6 |
// Copyright 2010 __MyCompanyName__. All rights reserved. |
|
7 |
// |
|
8 |
||
9 |
#import "FlagsViewController.h" |
|
10 |
#import "CommodityFunctions.h" |
|
11 |
||
12 |
@implementation FlagsViewController |
|
13 |
@synthesize teamDictionary, flagArray, lastIndexPath; |
|
14 |
||
15 |
||
16 |
-(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation { |
|
17 |
return rotationManager(interfaceOrientation); |
|
18 |
} |
|
19 |
||
20 |
||
21 |
#pragma mark - |
|
22 |
#pragma mark View lifecycle |
|
23 |
-(void) viewDidLoad { |
|
24 |
[super viewDidLoad]; |
|
25 |
||
26 |
self.flagArray = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:FLAGS_DIRECTORY() error:NULL]; |
|
3697 | 27 |
|
3662
a44406f4369b
polish polish polish polish (also: panning horizontal fix, panning momentum, settings page reworked yet again, memory leaks, crashes, segfaults)
koda
parents:
3547
diff
changeset
|
28 |
self.title = NSLocalizedString(@"Set team flag",@""); |
3547 | 29 |
} |
30 |
||
31 |
-(void) viewWillAppear:(BOOL)animated { |
|
32 |
[super viewWillAppear:animated]; |
|
33 |
[self.tableView reloadData]; |
|
34 |
[self.tableView setContentOffset:CGPointMake(0,0) animated:NO]; |
|
35 |
} |
|
36 |
||
37 |
||
38 |
#pragma mark - |
|
39 |
#pragma mark Table view data source |
|
40 |
-(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView { |
|
41 |
return 1; |
|
42 |
} |
|
43 |
||
44 |
-(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { |
|
45 |
return [flagArray count]; |
|
46 |
} |
|
47 |
||
48 |
// Customize the appearance of table view cells. |
|
49 |
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { |
|
3697 | 50 |
|
3547 | 51 |
static NSString *CellIdentifier = @"Cell"; |
3697 | 52 |
|
3547 | 53 |
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; |
54 |
if (cell == nil) { |
|
55 |
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; |
|
56 |
} |
|
3697 | 57 |
|
3547 | 58 |
NSString *flag = [flagArray objectAtIndex:[indexPath row]]; |
3697 | 59 |
|
3547 | 60 |
NSString *flagFile = [[NSString alloc] initWithFormat:@"%@/%@", FLAGS_DIRECTORY(), flag]; |
61 |
UIImage *flagSprite = [[UIImage alloc] initWithContentsOfFile:flagFile]; |
|
62 |
[flagFile release]; |
|
63 |
cell.imageView.image = flagSprite; |
|
64 |
[flagSprite release]; |
|
3697 | 65 |
|
3547 | 66 |
cell.textLabel.text = [flag stringByDeletingPathExtension]; |
67 |
if ([cell.textLabel.text isEqualToString:[self.teamDictionary objectForKey:@"flag"]]) { |
|
68 |
cell.accessoryType = UITableViewCellAccessoryCheckmark; |
|
69 |
self.lastIndexPath = indexPath; |
|
70 |
} else { |
|
71 |
cell.accessoryType = UITableViewCellAccessoryNone; |
|
72 |
} |
|
3697 | 73 |
|
3547 | 74 |
return cell; |
75 |
} |
|
76 |
||
77 |
||
78 |
#pragma mark - |
|
79 |
#pragma mark Table view delegate |
|
80 |
-(void) tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { |
|
81 |
int newRow = [indexPath row]; |
|
82 |
int oldRow = (lastIndexPath != nil) ? [lastIndexPath row] : -1; |
|
3697 | 83 |
|
3547 | 84 |
if (newRow != oldRow) { |
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"]; |
|
87 |
||
88 |
// tell our boss to write this new stuff on disk |
|
89 |
[[NSNotificationCenter defaultCenter] postNotificationName:@"setWriteNeedTeams" object:nil]; |
|
90 |
||
91 |
UITableViewCell *newCell = [aTableView cellForRowAtIndexPath:indexPath]; |
|
92 |
newCell.accessoryType = UITableViewCellAccessoryCheckmark; |
|
93 |
UITableViewCell *oldCell = [aTableView cellForRowAtIndexPath:lastIndexPath]; |
|
94 |
oldCell.accessoryType = UITableViewCellAccessoryNone; |
|
95 |
self.lastIndexPath = indexPath; |
|
96 |
[aTableView selectRowAtIndexPath:indexPath animated:YES scrollPosition:UITableViewScrollPositionNone]; |
|
97 |
} |
|
98 |
[aTableView deselectRowAtIndexPath:indexPath animated:YES]; |
|
99 |
[self.navigationController popViewControllerAnimated:YES]; |
|
100 |
} |
|
101 |
||
102 |
||
103 |
#pragma mark - |
|
104 |
#pragma mark Memory management |
|
105 |
-(void) didReceiveMemoryWarning { |
|
106 |
// Releases the view if it doesn't have a superview. |
|
107 |
[super didReceiveMemoryWarning]; |
|
108 |
// Relinquish ownership any cached data, images, etc that aren't in use. |
|
109 |
} |
|
110 |
||
111 |
-(void) viewDidUnload { |
|
112 |
self.teamDictionary = nil; |
|
113 |
self.lastIndexPath = nil; |
|
114 |
self.flagArray = nil; |
|
3662
a44406f4369b
polish polish polish polish (also: panning horizontal fix, panning momentum, settings page reworked yet again, memory leaks, crashes, segfaults)
koda
parents:
3547
diff
changeset
|
115 |
MSG_DIDUNLOAD(); |
3547 | 116 |
[super viewDidUnload]; |
117 |
} |
|
118 |
||
119 |
-(void) dealloc { |
|
120 |
[teamDictionary release]; |
|
121 |
[lastIndexPath release]; |
|
122 |
[flagArray release]; |
|
123 |
[super dealloc]; |
|
124 |
} |
|
125 |
||
126 |
||
127 |
@end |
|
128 |