author | koda |
Sun, 20 Jun 2010 18:35:59 +0200 | |
changeset 3523 | 6592fbb969da |
parent 3514 | 59dbd31e9953 |
child 3546 | ccf4854df294 |
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 |
static NSString *CellIdentifier = @"Cell"; |
52 |
||
53 |
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; |
|
3373 | 54 |
if (cell == nil) |
3339 | 55 |
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; |
56 |
||
3513
f589230fa21b
now it's possible to select the scheme file in the ifrontendfix a type about loading an image (iphone file system IS case senstive)
koda
parents:
3490
diff
changeset
|
57 |
NSString *grave = [self.graveArray objectAtIndex:[indexPath row]]; |
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 |
cell.textLabel.text = [grave stringByDeletingPathExtension]; |
3339 | 59 |
|
3513
f589230fa21b
now it's possible to select the scheme file in the ifrontendfix a type about loading an image (iphone file system IS case senstive)
koda
parents:
3490
diff
changeset
|
60 |
if ([grave isEqualToString:[self.teamDictionary objectForKey:@"grave"]]) { |
3339 | 61 |
cell.accessoryType = UITableViewCellAccessoryCheckmark; |
62 |
self.lastIndexPath = indexPath; |
|
63 |
} else { |
|
64 |
cell.accessoryType = UITableViewCellAccessoryNone; |
|
65 |
} |
|
3374
0d522416d97f
lazy loading for all the tables with images (might affect performance but ui feels much more responsive)
koda
parents:
3373
diff
changeset
|
66 |
|
0d522416d97f
lazy loading for all the tables with images (might affect performance but ui feels much more responsive)
koda
parents:
3373
diff
changeset
|
67 |
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
|
68 |
// 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
|
69 |
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
|
70 |
[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
|
71 |
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
|
72 |
[graveSprite release]; |
3339 | 73 |
|
74 |
return cell; |
|
75 |
} |
|
76 |
||
77 |
||
78 |
#pragma mark - |
|
79 |
#pragma mark Table view delegate |
|
3364 | 80 |
-(void) tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { |
3339 | 81 |
int newRow = [indexPath row]; |
82 |
int oldRow = (lastIndexPath != nil) ? [lastIndexPath row] : -1; |
|
83 |
||
84 |
if (newRow != oldRow) { |
|
3340 | 85 |
[teamDictionary setObject:[[graveArray objectAtIndex:newRow] stringByDeletingPathExtension] forKey:@"grave"]; |
3339 | 86 |
|
87 |
// tell our boss to write this new stuff on disk |
|
88 |
[[NSNotificationCenter defaultCenter] postNotificationName:@"setWriteNeedTeams" object:nil]; |
|
89 |
||
3374
0d522416d97f
lazy loading for all the tables with images (might affect performance but ui feels much more responsive)
koda
parents:
3373
diff
changeset
|
90 |
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
|
91 |
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
|
92 |
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
|
93 |
oldCell.accessoryType = UITableViewCellAccessoryNone; |
3339 | 94 |
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
|
95 |
[aTableView selectRowAtIndexPath:indexPath animated:YES scrollPosition:UITableViewScrollPositionNone]; |
3340 | 96 |
} |
3374
0d522416d97f
lazy loading for all the tables with images (might affect performance but ui feels much more responsive)
koda
parents:
3373
diff
changeset
|
97 |
[aTableView deselectRowAtIndexPath:indexPath animated:YES]; |
3339 | 98 |
[self.navigationController popViewControllerAnimated:YES]; |
99 |
} |
|
100 |
||
101 |
||
102 |
#pragma mark - |
|
103 |
#pragma mark Memory management |
|
104 |
- (void)didReceiveMemoryWarning { |
|
105 |
// Releases the view if it doesn't have a superview. |
|
106 |
[super didReceiveMemoryWarning]; |
|
107 |
// Relinquish ownership any cached data, images, etc that aren't in use. |
|
108 |
} |
|
109 |
||
110 |
- (void)viewDidUnload { |
|
111 |
self.lastIndexPath = nil; |
|
112 |
self.teamDictionary = nil; |
|
113 |
self.graveArray = nil; |
|
3490 | 114 |
[super viewDidUnload]; |
115 |
MSG_DIDUNLOAD(); |
|
3339 | 116 |
} |
117 |
||
118 |
- (void)dealloc { |
|
119 |
[graveArray release]; |
|
120 |
[teamDictionary release]; |
|
121 |
[lastIndexPath release]; |
|
122 |
[super dealloc]; |
|
123 |
} |
|
124 |
||
125 |
||
126 |
@end |
|
127 |