3305
|
1 |
//
|
|
2 |
// MasterViewController.m
|
|
3 |
// HedgewarsMobile
|
|
4 |
//
|
|
5 |
// Created by Vittorio on 27/03/10.
|
|
6 |
// Copyright 2010 __MyCompanyName__. All rights reserved.
|
|
7 |
//
|
|
8 |
|
|
9 |
#import "MasterViewController.h"
|
|
10 |
#import "DetailViewController.h"
|
3312
|
11 |
#import "GeneralSettingsViewController.h"
|
3305
|
12 |
#import "TeamSettingsViewController.h"
|
|
13 |
|
|
14 |
@implementation MasterViewController
|
3316
|
15 |
@synthesize detailViewController, optionList, controllers, lastIndexPath;
|
3305
|
16 |
|
|
17 |
#pragma mark -
|
|
18 |
#pragma mark View lifecycle
|
|
19 |
- (void)viewDidLoad {
|
|
20 |
[super viewDidLoad];
|
3316
|
21 |
|
|
22 |
// the list of selectable controllers
|
3305
|
23 |
optionList = [[NSArray alloc] initWithObjects:NSLocalizedString(@"General",@""),
|
|
24 |
NSLocalizedString(@"Teams",@""),
|
|
25 |
NSLocalizedString(@"Weapons",@""),
|
|
26 |
NSLocalizedString(@"Schemes",@""),
|
|
27 |
nil];
|
3316
|
28 |
// the "Done" button on top left
|
3312
|
29 |
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:0
|
|
30 |
target:self
|
|
31 |
action:@selector(dismissSplitView)];
|
3316
|
32 |
// list of allocated viewcontrollers (same in DetailViewController)
|
3312
|
33 |
NSMutableArray *array= [[NSMutableArray alloc] init];
|
3305
|
34 |
|
3312
|
35 |
GeneralSettingsViewController *generalSettingsViewController = [[GeneralSettingsViewController alloc]
|
|
36 |
initWithStyle:UITableViewStyleGrouped];
|
|
37 |
generalSettingsViewController.title = NSLocalizedString(@"General",@"");
|
|
38 |
generalSettingsViewController.navigationItem.hidesBackButton = YES;
|
|
39 |
[array addObject:generalSettingsViewController];
|
|
40 |
[generalSettingsViewController release];
|
|
41 |
|
|
42 |
TeamSettingsViewController *teamSettingsViewController = [[TeamSettingsViewController alloc]
|
|
43 |
initWithStyle:UITableViewStyleGrouped];
|
|
44 |
teamSettingsViewController.title = NSLocalizedString(@"Teams",@"");
|
|
45 |
teamSettingsViewController.navigationItem.hidesBackButton = YES;
|
|
46 |
[array addObject:teamSettingsViewController];
|
|
47 |
[teamSettingsViewController release];
|
|
48 |
|
|
49 |
self.controllers = array;
|
|
50 |
[array release];
|
3305
|
51 |
}
|
|
52 |
|
|
53 |
-(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
|
|
54 |
return (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
|
|
55 |
}
|
|
56 |
|
|
57 |
|
|
58 |
#pragma mark -
|
|
59 |
#pragma mark Table view data source
|
|
60 |
|
|
61 |
-(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView {
|
|
62 |
return 1;
|
|
63 |
}
|
|
64 |
|
|
65 |
|
|
66 |
-(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
|
|
67 |
return [optionList count];
|
|
68 |
}
|
|
69 |
|
|
70 |
|
|
71 |
// Customize the appearance of table view cells.
|
|
72 |
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
|
|
73 |
static NSString *CellIdentifier = @"Cell";
|
|
74 |
|
|
75 |
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
|
|
76 |
if (cell == nil) {
|
|
77 |
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
|
|
78 |
cell.textLabel.text = [optionList objectAtIndex:[indexPath row]];
|
|
79 |
}
|
|
80 |
|
|
81 |
return cell;
|
|
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 |
// Override to support rearranging the table view.
|
|
100 |
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
|
|
101 |
}
|
|
102 |
*/
|
|
103 |
|
|
104 |
/*
|
|
105 |
// Override to support conditional rearranging of the table view.
|
|
106 |
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
|
|
107 |
// Return NO if you do not want the item to be re-orderable.
|
|
108 |
return YES;
|
|
109 |
}
|
|
110 |
*/
|
|
111 |
|
|
112 |
#pragma mark -
|
|
113 |
#pragma mark Table view delegate
|
|
114 |
-(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
|
3316
|
115 |
int newRow = [indexPath row];
|
|
116 |
int oldRow = (lastIndexPath != nil) ? [lastIndexPath row] : 0;
|
3305
|
117 |
|
3316
|
118 |
if (newRow != oldRow) {
|
|
119 |
[detailViewController.navigationController popToRootViewControllerAnimated:NO];
|
|
120 |
|
|
121 |
UITableViewController *nextController = [self.controllers objectAtIndex:[indexPath row]];
|
|
122 |
[detailViewController.navigationController pushViewController:nextController animated:YES];
|
|
123 |
self.lastIndexPath = indexPath;
|
|
124 |
[self.tableView selectRowAtIndexPath:indexPath animated:YES scrollPosition:UITableViewScrollPositionNone];
|
|
125 |
}
|
|
126 |
[self.tableView deselectRowAtIndexPath:indexPath animated:YES];
|
3305
|
127 |
}
|
|
128 |
|
|
129 |
|
|
130 |
#pragma mark -
|
|
131 |
#pragma mark Memory management
|
|
132 |
-(void) didReceiveMemoryWarning {
|
|
133 |
// Releases the view if it doesn't have a superview.
|
|
134 |
[super didReceiveMemoryWarning];
|
|
135 |
// Relinquish ownership any cached data, images, etc that aren't in use.
|
|
136 |
}
|
|
137 |
|
|
138 |
- (void)dealloc {
|
|
139 |
[optionList release];
|
|
140 |
[detailViewController release];
|
|
141 |
[super dealloc];
|
|
142 |
}
|
|
143 |
|
|
144 |
-(IBAction) dismissSplitView {
|
|
145 |
[[NSNotificationCenter defaultCenter] postNotificationName:@"dismissModalView" object:nil];
|
|
146 |
}
|
|
147 |
|
|
148 |
@end
|
|
149 |
|