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"
|
3357
|
13 |
#import "WeaponSettingsViewController.h"
|
|
14 |
#import "SchemeSettingsViewController.h"
|
3335
|
15 |
#import "CommodityFunctions.h"
|
3305
|
16 |
|
|
17 |
@implementation MasterViewController
|
3357
|
18 |
@synthesize detailViewController, controllerNames, lastIndexPath;
|
3305
|
19 |
|
3335
|
20 |
|
|
21 |
-(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation {
|
|
22 |
return rotationManager(interfaceOrientation);
|
|
23 |
}
|
|
24 |
|
|
25 |
|
3305
|
26 |
#pragma mark -
|
|
27 |
#pragma mark View lifecycle
|
3405
|
28 |
-(void) viewDidLoad {
|
3305
|
29 |
[super viewDidLoad];
|
3316
|
30 |
|
|
31 |
// the list of selectable controllers
|
3357
|
32 |
controllerNames = [[NSArray alloc] initWithObjects:NSLocalizedString(@"General",@""),
|
|
33 |
NSLocalizedString(@"Teams",@""),
|
|
34 |
NSLocalizedString(@"Weapons",@""),
|
|
35 |
NSLocalizedString(@"Schemes",@""),
|
|
36 |
nil];
|
3316
|
37 |
// the "Done" button on top left
|
3357
|
38 |
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone
|
3312
|
39 |
target:self
|
|
40 |
action:@selector(dismissSplitView)];
|
3305
|
41 |
}
|
|
42 |
|
|
43 |
#pragma mark -
|
|
44 |
#pragma mark Table view data source
|
|
45 |
|
|
46 |
-(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView {
|
|
47 |
return 1;
|
|
48 |
}
|
|
49 |
|
|
50 |
-(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
|
3357
|
51 |
return [controllerNames count];
|
3305
|
52 |
}
|
|
53 |
|
|
54 |
// Customize the appearance of table view cells.
|
|
55 |
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
|
|
56 |
static NSString *CellIdentifier = @"Cell";
|
|
57 |
|
|
58 |
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
|
|
59 |
if (cell == nil) {
|
|
60 |
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
|
3357
|
61 |
cell.textLabel.text = [controllerNames objectAtIndex:[indexPath row]];
|
3305
|
62 |
}
|
|
63 |
|
|
64 |
return cell;
|
|
65 |
}
|
|
66 |
|
|
67 |
#pragma mark -
|
|
68 |
#pragma mark Table view delegate
|
|
69 |
-(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
|
3316
|
70 |
int newRow = [indexPath row];
|
3357
|
71 |
int oldRow = (lastIndexPath != nil) ? [lastIndexPath row] : -1;
|
3364
|
72 |
UIViewController *nextController = nil;
|
3305
|
73 |
|
3316
|
74 |
if (newRow != oldRow) {
|
3352
|
75 |
[self.tableView deselectRowAtIndexPath:lastIndexPath animated:YES];
|
3316
|
76 |
[detailViewController.navigationController popToRootViewControllerAnimated:NO];
|
|
77 |
|
3357
|
78 |
switch (newRow) {
|
|
79 |
case 0:
|
|
80 |
if (nil == generalSettingsViewController)
|
|
81 |
generalSettingsViewController = [[GeneralSettingsViewController alloc] initWithStyle:UITableViewStyleGrouped];
|
|
82 |
nextController = generalSettingsViewController;
|
|
83 |
break;
|
|
84 |
case 1:
|
|
85 |
if (nil == teamSettingsViewController)
|
|
86 |
teamSettingsViewController = [[TeamSettingsViewController alloc] initWithStyle:UITableViewStyleGrouped];
|
|
87 |
nextController = teamSettingsViewController;
|
|
88 |
break;
|
|
89 |
case 2:
|
|
90 |
if (nil == weaponSettingsViewController)
|
|
91 |
weaponSettingsViewController = [[WeaponSettingsViewController alloc] initWithStyle:UITableViewStyleGrouped];
|
|
92 |
nextController = weaponSettingsViewController;
|
|
93 |
break;
|
|
94 |
case 3:
|
|
95 |
if (nil == schemeSettingsViewController)
|
|
96 |
schemeSettingsViewController = [[SchemeSettingsViewController alloc] initWithStyle:UITableViewStyleGrouped];
|
|
97 |
nextController = schemeSettingsViewController;
|
|
98 |
break;
|
|
99 |
}
|
|
100 |
|
|
101 |
nextController.navigationItem.hidesBackButton = YES;
|
|
102 |
nextController.title = [controllerNames objectAtIndex:newRow];
|
3352
|
103 |
[detailViewController.navigationController pushViewController:nextController animated:NO];
|
3316
|
104 |
self.lastIndexPath = indexPath;
|
|
105 |
[self.tableView selectRowAtIndexPath:indexPath animated:YES scrollPosition:UITableViewScrollPositionNone];
|
|
106 |
}
|
3305
|
107 |
}
|
|
108 |
|
|
109 |
|
|
110 |
#pragma mark -
|
|
111 |
#pragma mark Memory management
|
|
112 |
-(void) didReceiveMemoryWarning {
|
|
113 |
// Releases the view if it doesn't have a superview.
|
|
114 |
[super didReceiveMemoryWarning];
|
|
115 |
// Relinquish ownership any cached data, images, etc that aren't in use.
|
|
116 |
}
|
|
117 |
|
3357
|
118 |
-(void) viewDidUnload {
|
|
119 |
self.detailViewController = nil;
|
|
120 |
self.controllerNames = nil;
|
|
121 |
self.lastIndexPath = nil;
|
|
122 |
generalSettingsViewController = nil;
|
|
123 |
teamSettingsViewController = nil;
|
|
124 |
weaponSettingsViewController = nil;
|
|
125 |
schemeSettingsViewController = nil;
|
|
126 |
[super viewDidUnload];
|
|
127 |
}
|
|
128 |
|
|
129 |
-(void) dealloc {
|
|
130 |
[controllerNames release];
|
3305
|
131 |
[detailViewController release];
|
3357
|
132 |
[lastIndexPath release];
|
|
133 |
[generalSettingsViewController release];
|
|
134 |
[teamSettingsViewController release];
|
|
135 |
[weaponSettingsViewController release];
|
|
136 |
[schemeSettingsViewController release];
|
3305
|
137 |
[super dealloc];
|
|
138 |
}
|
|
139 |
|
|
140 |
-(IBAction) dismissSplitView {
|
|
141 |
[[NSNotificationCenter defaultCenter] postNotificationName:@"dismissModalView" object:nil];
|
|
142 |
}
|
|
143 |
|
|
144 |
@end
|
|
145 |
|