3270
|
1 |
//
|
|
2 |
// HogHatViewController.m
|
|
3 |
// HedgewarsMobile
|
|
4 |
//
|
|
5 |
// Created by Vittorio on 02/04/10.
|
|
6 |
// Copyright 2010 __MyCompanyName__. All rights reserved.
|
|
7 |
//
|
|
8 |
|
|
9 |
#import "HogHatViewController.h"
|
|
10 |
|
|
11 |
|
|
12 |
@implementation HogHatViewController
|
|
13 |
@synthesize hatList, hog;
|
|
14 |
|
|
15 |
#pragma mark -
|
|
16 |
#pragma mark View lifecycle
|
|
17 |
|
|
18 |
|
|
19 |
- (void)viewDidLoad {
|
|
20 |
[super viewDidLoad];
|
|
21 |
|
|
22 |
//NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
|
|
23 |
NSString *hatPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingString:@"/Data/Graphics/Hats/"];
|
|
24 |
NSArray *array = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:hatPath
|
|
25 |
error:NULL];
|
|
26 |
self.hatList = array;
|
|
27 |
//NSLog(@"%@", hatList);
|
|
28 |
}
|
|
29 |
|
|
30 |
- (void)viewWillAppear:(BOOL)animated {
|
|
31 |
[super viewWillAppear:animated];
|
|
32 |
self.title = [hog objectForKey:@"hogname"];
|
|
33 |
[self.tableView reloadData];
|
|
34 |
}
|
|
35 |
|
|
36 |
/*
|
|
37 |
- (void)viewDidAppear:(BOOL)animated {
|
|
38 |
[super viewDidAppear:animated];
|
|
39 |
}
|
|
40 |
*/
|
|
41 |
/*
|
|
42 |
- (void)viewWillDisappear:(BOOL)animated {
|
|
43 |
[super viewWillDisappear:animated];
|
|
44 |
}
|
|
45 |
*/
|
|
46 |
/*
|
|
47 |
- (void)viewDidDisappear:(BOOL)animated {
|
|
48 |
[super viewDidDisappear:animated];
|
|
49 |
}
|
|
50 |
*/
|
|
51 |
|
|
52 |
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
|
|
53 |
// Override to allow orientations other than the default portrait orientation.
|
|
54 |
return YES;
|
|
55 |
}
|
|
56 |
|
|
57 |
|
|
58 |
#pragma mark -
|
|
59 |
#pragma mark Table view data source
|
|
60 |
-(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView {
|
|
61 |
return 2;
|
|
62 |
}
|
|
63 |
|
|
64 |
-(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
|
|
65 |
NSInteger rows;
|
|
66 |
if (0 == section)
|
|
67 |
rows = 1;
|
|
68 |
else
|
|
69 |
rows = [self.hatList count];
|
|
70 |
return rows;
|
|
71 |
}
|
|
72 |
|
|
73 |
// Customize the appearance of table view cells.
|
|
74 |
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
|
|
75 |
|
|
76 |
static NSString *CellIdentifier = @"Cell";
|
|
77 |
|
|
78 |
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
|
|
79 |
if (cell == nil) {
|
|
80 |
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
|
|
81 |
}
|
|
82 |
|
|
83 |
if (0 == [indexPath section])
|
|
84 |
cell.textLabel.text = [hog objectForKey:@"hogname"];
|
|
85 |
else
|
|
86 |
cell.textLabel.text = [[hatList objectAtIndex:[indexPath row]] stringByDeletingPathExtension];
|
|
87 |
|
|
88 |
return cell;
|
|
89 |
}
|
|
90 |
|
|
91 |
|
|
92 |
/*
|
|
93 |
// Override to support conditional editing of the table view.
|
|
94 |
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
|
|
95 |
// Return NO if you do not want the specified item to be editable.
|
|
96 |
return YES;
|
|
97 |
}
|
|
98 |
*/
|
|
99 |
|
|
100 |
|
|
101 |
/*
|
|
102 |
// Override to support editing the table view.
|
|
103 |
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
|
|
104 |
|
|
105 |
if (editingStyle == UITableViewCellEditingStyleDelete) {
|
|
106 |
// Delete the row from the data source
|
|
107 |
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:YES];
|
|
108 |
}
|
|
109 |
else if (editingStyle == UITableViewCellEditingStyleInsert) {
|
|
110 |
// Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
|
|
111 |
}
|
|
112 |
}
|
|
113 |
*/
|
|
114 |
|
|
115 |
|
|
116 |
/*
|
|
117 |
// Override to support rearranging the table view.
|
|
118 |
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
|
|
119 |
}
|
|
120 |
*/
|
|
121 |
|
|
122 |
|
|
123 |
/*
|
|
124 |
// Override to support conditional rearranging of the table view.
|
|
125 |
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
|
|
126 |
// Return NO if you do not want the item to be re-orderable.
|
|
127 |
return YES;
|
|
128 |
}
|
|
129 |
*/
|
|
130 |
|
|
131 |
|
|
132 |
#pragma mark -
|
|
133 |
#pragma mark Table view delegate
|
|
134 |
|
|
135 |
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
|
|
136 |
// Navigation logic may go here. Create and push another view controller.
|
|
137 |
/*
|
|
138 |
<#DetailViewController#> *detailViewController = [[<#DetailViewController#> alloc] initWithNibName:@"<#Nib name#>" bundle:nil];
|
|
139 |
// ...
|
|
140 |
// Pass the selected object to the new view controller.
|
|
141 |
[self.navigationController pushViewController:detailViewController animated:YES];
|
|
142 |
[detailViewController release];
|
|
143 |
*/
|
|
144 |
}
|
|
145 |
|
|
146 |
|
|
147 |
#pragma mark -
|
|
148 |
#pragma mark Memory management
|
|
149 |
|
|
150 |
- (void)didReceiveMemoryWarning {
|
|
151 |
// Releases the view if it doesn't have a superview.
|
|
152 |
[super didReceiveMemoryWarning];
|
|
153 |
|
|
154 |
// Relinquish ownership any cached data, images, etc that aren't in use.
|
|
155 |
}
|
|
156 |
|
|
157 |
- (void)viewDidUnload {
|
|
158 |
[super viewDidUnload];
|
|
159 |
self.hatList = nil;
|
|
160 |
self.hog = nil;
|
|
161 |
// Relinquish ownership of anything that can be recreated in viewDidLoad or on demand.
|
|
162 |
// For example: self.myOutlet = nil;
|
|
163 |
}
|
|
164 |
|
|
165 |
|
|
166 |
- (void)dealloc {
|
|
167 |
[hog release];
|
|
168 |
[hatList release];
|
|
169 |
[super dealloc];
|
|
170 |
}
|
|
171 |
|
|
172 |
|
|
173 |
@end
|
|
174 |
|