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];
|
3490
|
115 |
// Relinquish ownership any cached data, images, etc that aren't in use.
|
|
116 |
if (generalSettingsViewController.view.superview == nil)
|
|
117 |
generalSettingsViewController = nil;
|
|
118 |
if (teamSettingsViewController.view.superview == nil)
|
|
119 |
teamSettingsViewController = nil;
|
|
120 |
if (weaponSettingsViewController.view.superview == nil)
|
|
121 |
weaponSettingsViewController = nil;
|
|
122 |
if (schemeSettingsViewController.view.superview == nil)
|
|
123 |
schemeSettingsViewController = nil;
|
|
124 |
MSG_MEMCLEAN();
|
3305
|
125 |
}
|
|
126 |
|
3357
|
127 |
-(void) viewDidUnload {
|
|
128 |
self.detailViewController = nil;
|
|
129 |
self.controllerNames = nil;
|
|
130 |
self.lastIndexPath = nil;
|
|
131 |
generalSettingsViewController = nil;
|
|
132 |
teamSettingsViewController = nil;
|
|
133 |
weaponSettingsViewController = nil;
|
|
134 |
schemeSettingsViewController = nil;
|
|
135 |
[super viewDidUnload];
|
3490
|
136 |
MSG_DIDUNLOAD();
|
3357
|
137 |
}
|
|
138 |
|
|
139 |
-(void) dealloc {
|
|
140 |
[controllerNames release];
|
3305
|
141 |
[detailViewController release];
|
3357
|
142 |
[lastIndexPath release];
|
|
143 |
[generalSettingsViewController release];
|
|
144 |
[teamSettingsViewController release];
|
|
145 |
[weaponSettingsViewController release];
|
|
146 |
[schemeSettingsViewController release];
|
3305
|
147 |
[super dealloc];
|
|
148 |
}
|
|
149 |
|
|
150 |
-(IBAction) dismissSplitView {
|
|
151 |
[[NSNotificationCenter defaultCenter] postNotificationName:@"dismissModalView" object:nil];
|
|
152 |
}
|
|
153 |
|
|
154 |
@end
|
|
155 |
|