1 // |
|
2 // TeamSettingsViewController.m |
|
3 // HedgewarsMobile |
|
4 // |
|
5 // Created by Vittorio on 02/04/10. |
|
6 // Copyright 2010 __MyCompanyName__. All rights reserved. |
|
7 // |
|
8 |
|
9 #import "TeamSettingsViewController.h" |
|
10 #import "SingleTeamViewController.h" |
|
11 |
|
12 @implementation TeamSettingsViewController |
|
13 @synthesize list; |
|
14 |
|
15 #pragma mark - |
|
16 #pragma mark View lifecycle |
|
17 - (void)viewDidLoad { |
|
18 [super viewDidLoad]; |
|
19 |
|
20 NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); |
|
21 NSString *teamsDirectory = [[paths objectAtIndex:0] stringByAppendingString:@"Teams/"]; |
|
22 |
|
23 NSArray *contents = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:teamsDirectory |
|
24 error:NULL]; |
|
25 self.list = contents; |
|
26 |
|
27 // Uncomment the following line to preserve selection between presentations. |
|
28 // self.clearsSelectionOnViewWillAppear = NO; |
|
29 // Uncomment the following line to display an Edit button in the navigation bar for this view controller. |
|
30 self.navigationItem.rightBarButtonItem = self.editButtonItem; |
|
31 } |
|
32 |
|
33 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { |
|
34 // Override to allow orientations other than the default portrait orientation. |
|
35 return (interfaceOrientation == UIInterfaceOrientationLandscapeRight); |
|
36 } |
|
37 |
|
38 |
|
39 #pragma mark - |
|
40 #pragma mark Table view data source |
|
41 |
|
42 - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { |
|
43 // Return the number of sections. |
|
44 return 1; |
|
45 } |
|
46 |
|
47 |
|
48 - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { |
|
49 // Return the number of rows in the section. |
|
50 return [list count]; |
|
51 } |
|
52 |
|
53 |
|
54 // Customize the appearance of table view cells. |
|
55 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { |
|
56 |
|
57 static NSString *CellIdentifier = @"Cell"; |
|
58 |
|
59 UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; |
|
60 if (cell == nil) { |
|
61 cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; |
|
62 } |
|
63 |
|
64 NSUInteger row = [indexPath row]; |
|
65 NSString *rowString = [[list objectAtIndex:row] stringByDeletingPathExtension]; |
|
66 cell.textLabel.text = rowString; |
|
67 cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; |
|
68 //cell.imageView.image = [UIImage imageNamed:@"Default.png"]; |
|
69 //[rowString release]; |
|
70 |
|
71 return cell; |
|
72 } |
|
73 |
|
74 |
|
75 /* |
|
76 // Override to support conditional editing of the table view. |
|
77 - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath { |
|
78 // Return NO if you do not want the specified item to be editable. |
|
79 return YES; |
|
80 } |
|
81 */ |
|
82 |
|
83 |
|
84 /* |
|
85 // Override to support editing the table view. |
|
86 - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { |
|
87 |
|
88 if (editingStyle == UITableViewCellEditingStyleDelete) { |
|
89 // Delete the row from the data source |
|
90 [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:YES]; |
|
91 } |
|
92 else if (editingStyle == UITableViewCellEditingStyleInsert) { |
|
93 // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view |
|
94 } |
|
95 } |
|
96 */ |
|
97 |
|
98 |
|
99 /* |
|
100 // Override to support rearranging the table view. |
|
101 - (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath { |
|
102 } |
|
103 */ |
|
104 |
|
105 |
|
106 /* |
|
107 // Override to support conditional rearranging of the table view. |
|
108 - (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath { |
|
109 // Return NO if you do not want the item to be re-orderable. |
|
110 return YES; |
|
111 } |
|
112 */ |
|
113 |
|
114 |
|
115 #pragma mark - |
|
116 #pragma mark Table view delegate |
|
117 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { |
|
118 if (childController == nil) { |
|
119 childController = [[SingleTeamViewController alloc] initWithStyle:UITableViewStyleGrouped]; |
|
120 } |
|
121 |
|
122 NSInteger row = [indexPath row]; |
|
123 NSString *selectedTeam = [[list objectAtIndex:row] stringByDeletingPathExtension]; |
|
124 |
|
125 childController.teamName = selectedTeam; |
|
126 [self.navigationController pushViewController:childController animated:YES]; |
|
127 } |
|
128 |
|
129 /* |
|
130 -(void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath { |
|
131 UIAlertView *alert = [[UIAlertView alloc] initWithTitle: @"Hey, do you see the disclosure button?" |
|
132 message:@"If you're trying to drill down, touch that instead" |
|
133 delegate:nil |
|
134 cancelButtonTitle:@"Won't happen again" |
|
135 otherButtonTitles:nil]; |
|
136 [alert show]; |
|
137 [alert release]; |
|
138 } |
|
139 */ |
|
140 |
|
141 #pragma mark - |
|
142 #pragma mark Memory management |
|
143 |
|
144 - (void)didReceiveMemoryWarning { |
|
145 // Releases the view if it doesn't have a superview. |
|
146 [super didReceiveMemoryWarning]; |
|
147 |
|
148 // Relinquish ownership any cached data, images, etc that aren't in use. |
|
149 } |
|
150 |
|
151 /* |
|
152 - (void)viewDidUnload { |
|
153 // Relinquish ownership of anything that can be recreated in viewDidLoad or on demand. |
|
154 // For example: self.myOutlet = nil; |
|
155 } |
|
156 */ |
|
157 |
|
158 - (void)dealloc { |
|
159 [list release]; |
|
160 if (nil != childController) |
|
161 [childController release]; |
|
162 [super dealloc]; |
|
163 } |
|
164 |
|
165 |
|
166 @end |
|
167 |
|