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"
|
3335
|
13 |
#import "CommodityFunctions.h"
|
3305
|
14 |
|
|
15 |
@implementation MasterViewController
|
3316
|
16 |
@synthesize detailViewController, optionList, controllers, lastIndexPath;
|
3305
|
17 |
|
3335
|
18 |
|
|
19 |
-(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation {
|
|
20 |
return rotationManager(interfaceOrientation);
|
|
21 |
}
|
|
22 |
|
|
23 |
|
3305
|
24 |
#pragma mark -
|
|
25 |
#pragma mark View lifecycle
|
|
26 |
- (void)viewDidLoad {
|
|
27 |
[super viewDidLoad];
|
3316
|
28 |
|
|
29 |
// the list of selectable controllers
|
3305
|
30 |
optionList = [[NSArray alloc] initWithObjects:NSLocalizedString(@"General",@""),
|
|
31 |
NSLocalizedString(@"Teams",@""),
|
|
32 |
NSLocalizedString(@"Weapons",@""),
|
|
33 |
NSLocalizedString(@"Schemes",@""),
|
|
34 |
nil];
|
3316
|
35 |
// the "Done" button on top left
|
3312
|
36 |
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:0
|
|
37 |
target:self
|
|
38 |
action:@selector(dismissSplitView)];
|
3316
|
39 |
// list of allocated viewcontrollers (same in DetailViewController)
|
3312
|
40 |
NSMutableArray *array= [[NSMutableArray alloc] init];
|
3305
|
41 |
|
3312
|
42 |
GeneralSettingsViewController *generalSettingsViewController = [[GeneralSettingsViewController alloc]
|
|
43 |
initWithStyle:UITableViewStyleGrouped];
|
|
44 |
generalSettingsViewController.title = NSLocalizedString(@"General",@"");
|
|
45 |
generalSettingsViewController.navigationItem.hidesBackButton = YES;
|
|
46 |
[array addObject:generalSettingsViewController];
|
|
47 |
[generalSettingsViewController release];
|
|
48 |
|
|
49 |
TeamSettingsViewController *teamSettingsViewController = [[TeamSettingsViewController alloc]
|
|
50 |
initWithStyle:UITableViewStyleGrouped];
|
|
51 |
teamSettingsViewController.title = NSLocalizedString(@"Teams",@"");
|
|
52 |
teamSettingsViewController.navigationItem.hidesBackButton = YES;
|
|
53 |
[array addObject:teamSettingsViewController];
|
|
54 |
[teamSettingsViewController release];
|
|
55 |
|
|
56 |
self.controllers = array;
|
|
57 |
[array release];
|
3305
|
58 |
}
|
|
59 |
|
|
60 |
#pragma mark -
|
|
61 |
#pragma mark Table view data source
|
|
62 |
|
|
63 |
-(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView {
|
|
64 |
return 1;
|
|
65 |
}
|
|
66 |
|
|
67 |
|
|
68 |
-(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
|
|
69 |
return [optionList count];
|
|
70 |
}
|
|
71 |
|
|
72 |
|
|
73 |
// Customize the appearance of table view cells.
|
|
74 |
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
|
|
75 |
static NSString *CellIdentifier = @"Cell";
|
|
76 |
|
|
77 |
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
|
|
78 |
if (cell == nil) {
|
|
79 |
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
|
|
80 |
cell.textLabel.text = [optionList objectAtIndex:[indexPath row]];
|
|
81 |
}
|
|
82 |
|
|
83 |
return cell;
|
|
84 |
}
|
|
85 |
|
|
86 |
/*
|
|
87 |
// Override to support editing the table view.
|
|
88 |
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
|
|
89 |
|
|
90 |
if (editingStyle == UITableViewCellEditingStyleDelete) {
|
|
91 |
// Delete the row from the data source
|
|
92 |
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:YES];
|
|
93 |
}
|
|
94 |
else if (editingStyle == UITableViewCellEditingStyleInsert) {
|
|
95 |
// Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
|
|
96 |
}
|
|
97 |
}
|
|
98 |
*/
|
|
99 |
|
|
100 |
/*
|
|
101 |
// Override to support rearranging the table view.
|
|
102 |
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
|
|
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 |
#pragma mark -
|
|
115 |
#pragma mark Table view delegate
|
|
116 |
-(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
|
3316
|
117 |
int newRow = [indexPath row];
|
|
118 |
int oldRow = (lastIndexPath != nil) ? [lastIndexPath row] : 0;
|
3305
|
119 |
|
3316
|
120 |
if (newRow != oldRow) {
|
|
121 |
[detailViewController.navigationController popToRootViewControllerAnimated:NO];
|
|
122 |
|
|
123 |
UITableViewController *nextController = [self.controllers objectAtIndex:[indexPath row]];
|
|
124 |
[detailViewController.navigationController pushViewController:nextController animated:YES];
|
|
125 |
self.lastIndexPath = indexPath;
|
|
126 |
[self.tableView selectRowAtIndexPath:indexPath animated:YES scrollPosition:UITableViewScrollPositionNone];
|
|
127 |
}
|
|
128 |
[self.tableView deselectRowAtIndexPath:indexPath animated:YES];
|
3305
|
129 |
}
|
|
130 |
|
|
131 |
|
|
132 |
#pragma mark -
|
|
133 |
#pragma mark Memory management
|
|
134 |
-(void) didReceiveMemoryWarning {
|
|
135 |
// Releases the view if it doesn't have a superview.
|
|
136 |
[super didReceiveMemoryWarning];
|
|
137 |
// Relinquish ownership any cached data, images, etc that aren't in use.
|
|
138 |
}
|
|
139 |
|
|
140 |
- (void)dealloc {
|
|
141 |
[optionList release];
|
|
142 |
[detailViewController release];
|
|
143 |
[super dealloc];
|
|
144 |
}
|
|
145 |
|
|
146 |
-(IBAction) dismissSplitView {
|
|
147 |
[[NSNotificationCenter defaultCenter] postNotificationName:@"dismissModalView" object:nil];
|
|
148 |
}
|
|
149 |
|
|
150 |
@end
|
|
151 |
|