author | nemo |
Mon, 17 May 2010 02:54:56 +0000 | |
changeset 3470 | 2b0c88693535 |
parent 3374 | 0d522416d97f |
child 3490 | 016b3172b645 |
permissions | -rw-r--r-- |
3339 | 1 |
// |
3352 | 2 |
// GravesViewController.m |
3339 | 3 |
// HedgewarsMobile |
4 |
// |
|
5 |
// Created by Vittorio on 02/04/10. |
|
6 |
// Copyright 2010 __MyCompanyName__. All rights reserved. |
|
7 |
// |
|
8 |
||
3340 | 9 |
#import "GravesViewController.h" |
3339 | 10 |
#import "CommodityFunctions.h" |
3352 | 11 |
#import "UIImageExtra.h" |
3339 | 12 |
|
13 |
@implementation GravesViewController |
|
3374
0d522416d97f
lazy loading for all the tables with images (might affect performance but ui feels much more responsive)
koda
parents:
3373
diff
changeset
|
14 |
@synthesize teamDictionary, graveArray, lastIndexPath; |
3339 | 15 |
|
16 |
||
17 |
-(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation { |
|
18 |
return rotationManager(interfaceOrientation); |
|
19 |
} |
|
20 |
||
21 |
||
22 |
#pragma mark - |
|
23 |
#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:
3373
diff
changeset
|
24 |
-(void) viewDidLoad { |
3339 | 25 |
[super viewDidLoad]; |
26 |
||
3374
0d522416d97f
lazy loading for all the tables with images (might affect performance but ui feels much more responsive)
koda
parents:
3373
diff
changeset
|
27 |
// load all the grave names and store them into graveArray |
0d522416d97f
lazy loading for all the tables with images (might affect performance but ui feels much more responsive)
koda
parents:
3373
diff
changeset
|
28 |
self.graveArray = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:GRAVES_DIRECTORY() error:NULL]; |
3339 | 29 |
} |
30 |
||
3374
0d522416d97f
lazy loading for all the tables with images (might affect performance but ui feels much more responsive)
koda
parents:
3373
diff
changeset
|
31 |
-(void) viewWillAppear:(BOOL)animated { |
3339 | 32 |
[super viewWillAppear:animated]; |
3374
0d522416d97f
lazy loading for all the tables with images (might affect performance but ui feels much more responsive)
koda
parents:
3373
diff
changeset
|
33 |
[self.tableView reloadData]; |
3339 | 34 |
// this moves the tableview to the top |
35 |
[self.tableView setContentOffset:CGPointMake(0,0) animated:NO]; |
|
36 |
} |
|
37 |
||
38 |
||
39 |
#pragma mark - |
|
40 |
#pragma mark Table view data source |
|
41 |
-(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView { |
|
42 |
return 1; |
|
43 |
} |
|
44 |
||
45 |
-(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { |
|
46 |
return [self.graveArray count]; |
|
47 |
} |
|
48 |
||
49 |
// 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:
3373
diff
changeset
|
50 |
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { |
3339 | 51 |
|
52 |
static NSString *CellIdentifier = @"Cell"; |
|
53 |
||
54 |
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; |
|
3373 | 55 |
if (cell == nil) |
3339 | 56 |
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; |
57 |
||
3374
0d522416d97f
lazy loading for all the tables with images (might affect performance but ui feels much more responsive)
koda
parents:
3373
diff
changeset
|
58 |
NSString *grave = [graveArray objectAtIndex:[indexPath row]]; |
0d522416d97f
lazy loading for all the tables with images (might affect performance but ui feels much more responsive)
koda
parents:
3373
diff
changeset
|
59 |
cell.textLabel.text = [grave stringByDeletingPathExtension]; |
3339 | 60 |
|
3340 | 61 |
if ([grave isEqualToString:[teamDictionary objectForKey:@"grave"]]) { |
3339 | 62 |
cell.accessoryType = UITableViewCellAccessoryCheckmark; |
63 |
self.lastIndexPath = indexPath; |
|
64 |
} else { |
|
65 |
cell.accessoryType = UITableViewCellAccessoryNone; |
|
66 |
} |
|
3374
0d522416d97f
lazy loading for all the tables with images (might affect performance but ui feels much more responsive)
koda
parents:
3373
diff
changeset
|
67 |
|
0d522416d97f
lazy loading for all the tables with images (might affect performance but ui feels much more responsive)
koda
parents:
3373
diff
changeset
|
68 |
NSString *graveFilePath = [[NSString alloc] initWithFormat:@"%@/%@",GRAVES_DIRECTORY(),grave]; |
0d522416d97f
lazy loading for all the tables with images (might affect performance but ui feels much more responsive)
koda
parents:
3373
diff
changeset
|
69 |
// because we also have multi frame graves, let's take the first one only |
0d522416d97f
lazy loading for all the tables with images (might affect performance but ui feels much more responsive)
koda
parents:
3373
diff
changeset
|
70 |
UIImage *graveSprite = [[UIImage alloc] initWithContentsOfFile:graveFilePath andCutAt:CGRectMake(0, 0, 32, 32)]; |
0d522416d97f
lazy loading for all the tables with images (might affect performance but ui feels much more responsive)
koda
parents:
3373
diff
changeset
|
71 |
[graveFilePath release]; |
0d522416d97f
lazy loading for all the tables with images (might affect performance but ui feels much more responsive)
koda
parents:
3373
diff
changeset
|
72 |
cell.imageView.image = graveSprite; |
0d522416d97f
lazy loading for all the tables with images (might affect performance but ui feels much more responsive)
koda
parents:
3373
diff
changeset
|
73 |
[graveSprite release]; |
3339 | 74 |
|
75 |
return cell; |
|
76 |
} |
|
77 |
||
78 |
||
79 |
#pragma mark - |
|
80 |
#pragma mark Table view delegate |
|
3364 | 81 |
-(void) tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { |
3339 | 82 |
int newRow = [indexPath row]; |
83 |
int oldRow = (lastIndexPath != nil) ? [lastIndexPath row] : -1; |
|
84 |
||
85 |
if (newRow != oldRow) { |
|
3340 | 86 |
[teamDictionary setObject:[[graveArray objectAtIndex:newRow] stringByDeletingPathExtension] forKey:@"grave"]; |
3339 | 87 |
|
88 |
// tell our boss to write this new stuff on disk |
|
89 |
[[NSNotificationCenter defaultCenter] postNotificationName:@"setWriteNeedTeams" object:nil]; |
|
90 |
||
3374
0d522416d97f
lazy loading for all the tables with images (might affect performance but ui feels much more responsive)
koda
parents:
3373
diff
changeset
|
91 |
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:
3373
diff
changeset
|
92 |
newCell.accessoryType = UITableViewCellAccessoryCheckmark; |
0d522416d97f
lazy loading for all the tables with images (might affect performance but ui feels much more responsive)
koda
parents:
3373
diff
changeset
|
93 |
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:
3373
diff
changeset
|
94 |
oldCell.accessoryType = UITableViewCellAccessoryNone; |
3339 | 95 |
self.lastIndexPath = indexPath; |
3374
0d522416d97f
lazy loading for all the tables with images (might affect performance but ui feels much more responsive)
koda
parents:
3373
diff
changeset
|
96 |
[aTableView selectRowAtIndexPath:indexPath animated:YES scrollPosition:UITableViewScrollPositionNone]; |
3340 | 97 |
} |
3374
0d522416d97f
lazy loading for all the tables with images (might affect performance but ui feels much more responsive)
koda
parents:
3373
diff
changeset
|
98 |
[aTableView deselectRowAtIndexPath:indexPath animated:YES]; |
3339 | 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 |
[super viewDidUnload]; |
|
113 |
self.lastIndexPath = nil; |
|
114 |
self.teamDictionary = nil; |
|
115 |
self.graveArray = nil; |
|
116 |
} |
|
117 |
||
118 |
- (void)dealloc { |
|
119 |
[graveArray release]; |
|
120 |
[teamDictionary release]; |
|
121 |
[lastIndexPath release]; |
|
122 |
[super dealloc]; |
|
123 |
} |
|
124 |
||
125 |
||
126 |
@end |
|
127 |