author | koda |
Thu, 17 Jun 2010 20:30:39 +0200 | |
changeset 3514 | 59dbd31e9953 |
parent 3490 | cocoaTouch/FlagsViewController.m@016b3172b645 |
child 3546 | ccf4854df294 |
permissions | -rw-r--r-- |
3325 | 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 |
|
3374
0d522416d97f
lazy loading for all the tables with images (might affect performance but ui feels much more responsive)
koda
parents:
3335
diff
changeset
|
13 |
@synthesize teamDictionary, flagArray, lastIndexPath; |
3325 | 14 |
|
15 |
||
3335 | 16 |
-(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation { |
17 |
return rotationManager(interfaceOrientation); |
|
3325 | 18 |
} |
19 |
||
3335 | 20 |
|
3325 | 21 |
#pragma mark - |
22 |
#pragma mark View lifecycle |
|
3374
0d522416d97f
lazy loading for all the tables with images (might affect performance but ui feels much more responsive)
koda
parents:
3335
diff
changeset
|
23 |
-(void) viewDidLoad { |
3325 | 24 |
[super viewDidLoad]; |
25 |
||
3374
0d522416d97f
lazy loading for all the tables with images (might affect performance but ui feels much more responsive)
koda
parents:
3335
diff
changeset
|
26 |
self.flagArray = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:FLAGS_DIRECTORY() error:NULL]; |
3325 | 27 |
} |
28 |
||
3374
0d522416d97f
lazy loading for all the tables with images (might affect performance but ui feels much more responsive)
koda
parents:
3335
diff
changeset
|
29 |
-(void) viewWillAppear:(BOOL)animated { |
3325 | 30 |
[super viewWillAppear:animated]; |
31 |
[self.tableView reloadData]; |
|
32 |
[self.tableView setContentOffset:CGPointMake(0,0) animated:NO]; |
|
33 |
} |
|
34 |
||
35 |
||
36 |
#pragma mark - |
|
37 |
#pragma mark Table view data source |
|
3374
0d522416d97f
lazy loading for all the tables with images (might affect performance but ui feels much more responsive)
koda
parents:
3335
diff
changeset
|
38 |
-(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView { |
3325 | 39 |
return 1; |
40 |
} |
|
41 |
||
3374
0d522416d97f
lazy loading for all the tables with images (might affect performance but ui feels much more responsive)
koda
parents:
3335
diff
changeset
|
42 |
-(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { |
3325 | 43 |
return [flagArray count]; |
44 |
} |
|
45 |
||
46 |
// Customize the appearance of table view cells. |
|
3374
0d522416d97f
lazy loading for all the tables with images (might affect performance but ui feels much more responsive)
koda
parents:
3335
diff
changeset
|
47 |
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { |
3325 | 48 |
|
49 |
static NSString *CellIdentifier = @"Cell"; |
|
50 |
||
51 |
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; |
|
52 |
if (cell == nil) { |
|
53 |
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; |
|
54 |
} |
|
55 |
||
3374
0d522416d97f
lazy loading for all the tables with images (might affect performance but ui feels much more responsive)
koda
parents:
3335
diff
changeset
|
56 |
NSString *flag = [flagArray objectAtIndex:[indexPath row]]; |
0d522416d97f
lazy loading for all the tables with images (might affect performance but ui feels much more responsive)
koda
parents:
3335
diff
changeset
|
57 |
|
0d522416d97f
lazy loading for all the tables with images (might affect performance but ui feels much more responsive)
koda
parents:
3335
diff
changeset
|
58 |
NSString *flagFile = [[NSString alloc] initWithFormat:@"%@/%@", FLAGS_DIRECTORY(), flag]; |
0d522416d97f
lazy loading for all the tables with images (might affect performance but ui feels much more responsive)
koda
parents:
3335
diff
changeset
|
59 |
UIImage *flagSprite = [[UIImage alloc] initWithContentsOfFile:flagFile]; |
0d522416d97f
lazy loading for all the tables with images (might affect performance but ui feels much more responsive)
koda
parents:
3335
diff
changeset
|
60 |
[flagFile release]; |
0d522416d97f
lazy loading for all the tables with images (might affect performance but ui feels much more responsive)
koda
parents:
3335
diff
changeset
|
61 |
cell.imageView.image = flagSprite; |
0d522416d97f
lazy loading for all the tables with images (might affect performance but ui feels much more responsive)
koda
parents:
3335
diff
changeset
|
62 |
[flagSprite release]; |
0d522416d97f
lazy loading for all the tables with images (might affect performance but ui feels much more responsive)
koda
parents:
3335
diff
changeset
|
63 |
|
0d522416d97f
lazy loading for all the tables with images (might affect performance but ui feels much more responsive)
koda
parents:
3335
diff
changeset
|
64 |
cell.textLabel.text = [flag stringByDeletingPathExtension]; |
3325 | 65 |
if ([cell.textLabel.text isEqualToString:[self.teamDictionary objectForKey:@"flag"]]) { |
66 |
cell.accessoryType = UITableViewCellAccessoryCheckmark; |
|
67 |
self.lastIndexPath = indexPath; |
|
68 |
} else { |
|
69 |
cell.accessoryType = UITableViewCellAccessoryNone; |
|
70 |
} |
|
71 |
||
72 |
return cell; |
|
73 |
} |
|
74 |
||
75 |
||
76 |
#pragma mark - |
|
77 |
#pragma mark Table view delegate |
|
3374
0d522416d97f
lazy loading for all the tables with images (might affect performance but ui feels much more responsive)
koda
parents:
3335
diff
changeset
|
78 |
-(void) tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { |
3325 | 79 |
int newRow = [indexPath row]; |
80 |
int oldRow = (lastIndexPath != nil) ? [lastIndexPath row] : -1; |
|
81 |
||
82 |
if (newRow != oldRow) { |
|
83 |
// if the two selected rows differ update data on the hog dictionary and reload table content |
|
84 |
[self.teamDictionary setValue:[[flagArray objectAtIndex:newRow] stringByDeletingPathExtension] forKey:@"flag"]; |
|
85 |
||
86 |
// tell our boss to write this new stuff on disk |
|
87 |
[[NSNotificationCenter defaultCenter] postNotificationName:@"setWriteNeedTeams" object:nil]; |
|
88 |
||
3374
0d522416d97f
lazy loading for all the tables with images (might affect performance but ui feels much more responsive)
koda
parents:
3335
diff
changeset
|
89 |
UITableViewCell *newCell = [aTableView cellForRowAtIndexPath:indexPath]; |
0d522416d97f
lazy loading for all the tables with images (might affect performance but ui feels much more responsive)
koda
parents:
3335
diff
changeset
|
90 |
newCell.accessoryType = UITableViewCellAccessoryCheckmark; |
0d522416d97f
lazy loading for all the tables with images (might affect performance but ui feels much more responsive)
koda
parents:
3335
diff
changeset
|
91 |
UITableViewCell *oldCell = [aTableView cellForRowAtIndexPath:lastIndexPath]; |
0d522416d97f
lazy loading for all the tables with images (might affect performance but ui feels much more responsive)
koda
parents:
3335
diff
changeset
|
92 |
oldCell.accessoryType = UITableViewCellAccessoryNone; |
3325 | 93 |
self.lastIndexPath = indexPath; |
3374
0d522416d97f
lazy loading for all the tables with images (might affect performance but ui feels much more responsive)
koda
parents:
3335
diff
changeset
|
94 |
[aTableView selectRowAtIndexPath:indexPath animated:YES scrollPosition:UITableViewScrollPositionNone]; |
3325 | 95 |
} |
3374
0d522416d97f
lazy loading for all the tables with images (might affect performance but ui feels much more responsive)
koda
parents:
3335
diff
changeset
|
96 |
[aTableView deselectRowAtIndexPath:indexPath animated:YES]; |
3325 | 97 |
[self.navigationController popViewControllerAnimated:YES]; |
98 |
} |
|
99 |
||
100 |
||
101 |
#pragma mark - |
|
102 |
#pragma mark Memory management |
|
3374
0d522416d97f
lazy loading for all the tables with images (might affect performance but ui feels much more responsive)
koda
parents:
3335
diff
changeset
|
103 |
-(void) didReceiveMemoryWarning { |
3325 | 104 |
// Releases the view if it doesn't have a superview. |
105 |
[super didReceiveMemoryWarning]; |
|
106 |
// Relinquish ownership any cached data, images, etc that aren't in use. |
|
107 |
} |
|
108 |
||
3374
0d522416d97f
lazy loading for all the tables with images (might affect performance but ui feels much more responsive)
koda
parents:
3335
diff
changeset
|
109 |
-(void) viewDidUnload { |
3325 | 110 |
self.teamDictionary = nil; |
111 |
self.lastIndexPath = nil; |
|
112 |
self.flagArray = nil; |
|
113 |
[super viewDidUnload]; |
|
3490 | 114 |
MSG_DIDUNLOAD(); |
3325 | 115 |
} |
116 |
||
3374
0d522416d97f
lazy loading for all the tables with images (might affect performance but ui feels much more responsive)
koda
parents:
3335
diff
changeset
|
117 |
-(void) dealloc { |
3325 | 118 |
[teamDictionary release]; |
119 |
[lastIndexPath release]; |
|
120 |
[flagArray release]; |
|
121 |
[super dealloc]; |
|
122 |
} |
|
123 |
||
124 |
||
125 |
@end |
|
126 |