3305
|
1 |
//
|
|
2 |
// DetailViewController.m
|
|
3 |
// HedgewarsMobile
|
|
4 |
//
|
|
5 |
// Created by Vittorio on 27/03/10.
|
|
6 |
// Copyright 2010 __MyCompanyName__. All rights reserved.
|
|
7 |
//
|
|
8 |
|
|
9 |
#import "DetailViewController.h"
|
3312
|
10 |
#import "SDL_uikitappdelegate.h"
|
3356
|
11 |
#import "GeneralSettingsViewController.h"
|
3305
|
12 |
#import "TeamSettingsViewController.h"
|
3356
|
13 |
#import "WeaponSettingsViewController.h"
|
|
14 |
#import "SchemeSettingsViewController.h"
|
3335
|
15 |
#import "CommodityFunctions.h"
|
3305
|
16 |
|
|
17 |
@implementation DetailViewController
|
3490
|
18 |
@synthesize controllerNames,popoverController;
|
3305
|
19 |
|
|
20 |
|
3335
|
21 |
-(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation {
|
|
22 |
return rotationManager(interfaceOrientation);
|
|
23 |
}
|
|
24 |
|
3490
|
25 |
-(void) willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration{
|
|
26 |
self.view.frame = CGRectMake(0, 0, 1024, 1024);
|
|
27 |
}
|
|
28 |
|
3357
|
29 |
-(void) viewDidLoad {
|
3305
|
30 |
self.title = NSLocalizedString(@"Settings",@"");
|
|
31 |
|
3316
|
32 |
// allocate controllers and store them into the array
|
3356
|
33 |
NSArray *array= [[NSArray alloc] initWithObjects:NSLocalizedString(@"General",@""),
|
|
34 |
NSLocalizedString(@"Teams",@""),
|
|
35 |
NSLocalizedString(@"Weapons",@""),
|
|
36 |
NSLocalizedString(@"Schemes",@""),
|
|
37 |
nil];
|
|
38 |
self.controllerNames = array;
|
3305
|
39 |
[array release];
|
3316
|
40 |
|
|
41 |
// on ipad make the general setting the first view, on iphone add the "Done" button on top left
|
|
42 |
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
|
3356
|
43 |
|
3357
|
44 |
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(112, 112, 480, 320)];
|
|
45 |
label.text = @"Press the buttons on the left";
|
|
46 |
label.font = [UIFont systemFontOfSize:20];
|
|
47 |
label.textAlignment = UITextAlignmentCenter;
|
|
48 |
[self.view addSubview:label];
|
|
49 |
[label release];
|
|
50 |
|
3356
|
51 |
//[self.navigationController pushViewController:nextController animated:NO];
|
3316
|
52 |
} else {
|
3356
|
53 |
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone
|
|
54 |
target:self
|
|
55 |
action:@selector(dismissSplitView)];
|
3316
|
56 |
}
|
|
57 |
|
3305
|
58 |
[super viewDidLoad];
|
|
59 |
}
|
|
60 |
|
|
61 |
|
|
62 |
#pragma mark -
|
|
63 |
#pragma mark Table view data source
|
|
64 |
-(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView {
|
3357
|
65 |
// don't display
|
|
66 |
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
|
|
67 |
return 0;
|
|
68 |
else
|
|
69 |
return 1;
|
3305
|
70 |
}
|
|
71 |
|
|
72 |
-(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
|
3356
|
73 |
return [controllerNames count];
|
3305
|
74 |
}
|
|
75 |
|
|
76 |
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
|
|
77 |
static NSString *CellIdentifier = @"Cell";
|
|
78 |
|
|
79 |
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
|
|
80 |
if (cell == nil) {
|
|
81 |
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
|
|
82 |
reuseIdentifier:CellIdentifier] autorelease];
|
|
83 |
}
|
|
84 |
|
|
85 |
NSInteger row = [indexPath row];
|
|
86 |
|
3356
|
87 |
cell.textLabel.text = [controllerNames objectAtIndex:row];
|
3305
|
88 |
cell.imageView.image = [UIImage imageNamed:@"Icon.png"];
|
|
89 |
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
|
|
90 |
|
|
91 |
return cell;
|
|
92 |
}
|
|
93 |
|
3357
|
94 |
#pragma mark -
|
|
95 |
#pragma mark Table view delegate
|
3305
|
96 |
-(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
|
|
97 |
NSInteger row = [indexPath row];
|
3364
|
98 |
UIViewController *nextController = nil;
|
3356
|
99 |
|
|
100 |
switch (row) {
|
|
101 |
case 0:
|
|
102 |
if (nil == generalSettingsViewController)
|
|
103 |
generalSettingsViewController = [[GeneralSettingsViewController alloc] initWithStyle:UITableViewStyleGrouped];
|
|
104 |
nextController = generalSettingsViewController;
|
|
105 |
break;
|
|
106 |
case 1:
|
|
107 |
if (nil == teamSettingsViewController)
|
|
108 |
teamSettingsViewController = [[TeamSettingsViewController alloc] initWithStyle:UITableViewStyleGrouped];
|
|
109 |
nextController = teamSettingsViewController;
|
|
110 |
break;
|
|
111 |
case 2:
|
|
112 |
if (nil == weaponSettingsViewController)
|
|
113 |
weaponSettingsViewController = [[WeaponSettingsViewController alloc] initWithStyle:UITableViewStyleGrouped];
|
|
114 |
nextController = weaponSettingsViewController;
|
|
115 |
break;
|
|
116 |
case 3:
|
|
117 |
if (nil == schemeSettingsViewController)
|
|
118 |
schemeSettingsViewController = [[SchemeSettingsViewController alloc] initWithStyle:UITableViewStyleGrouped];
|
|
119 |
nextController = schemeSettingsViewController;
|
|
120 |
break;
|
|
121 |
}
|
|
122 |
|
|
123 |
nextController.title = [controllerNames objectAtIndex:row];
|
3305
|
124 |
[self.navigationController pushViewController:nextController animated:YES];
|
|
125 |
}
|
|
126 |
|
3490
|
127 |
-(IBAction) dismissSplitView {
|
|
128 |
[[NSNotificationCenter defaultCenter] postNotificationName:@"dismissModalView" object:nil];
|
3305
|
129 |
}
|
|
130 |
|
|
131 |
#pragma mark -
|
3490
|
132 |
#pragma mark splitview support
|
|
133 |
-(void) splitViewController:(UISplitViewController *)svc popoverController:(UIPopoverController *)pc willPresentViewController:(UIViewController *)aViewController {
|
|
134 |
if (popoverController != nil) {
|
|
135 |
[popoverController dismissPopoverAnimated:YES];
|
|
136 |
}
|
3305
|
137 |
}
|
|
138 |
|
3490
|
139 |
// Called when the master view controller is about to be hidden
|
|
140 |
-(void) splitViewController: (UISplitViewController*)svc willHideViewController:(UIViewController *)aViewController
|
|
141 |
withBarButtonItem:(UIBarButtonItem*)barButtonItem forPopoverController: (UIPopoverController*)pc {
|
|
142 |
|
|
143 |
/* barButtonItem.title = @"Master View";
|
|
144 |
UIToolbar *toolbar = self.parentViewController.navigationController.toolbar;
|
|
145 |
NSMutableArray *items = [[toolbar items] mutableCopy];
|
|
146 |
[items insertObject:barButtonItem atIndex:0];
|
|
147 |
[toolbar setItems:items animated:YES];
|
|
148 |
|
|
149 |
[items release];
|
|
150 |
|
|
151 |
self.popoverController = pc;*/
|
|
152 |
barButtonItem.title = aViewController.title;
|
|
153 |
self.navigationItem.rightBarButtonItem = barButtonItem;
|
3305
|
154 |
}
|
3490
|
155 |
|
|
156 |
// Called when the master view controller is about to appear
|
|
157 |
-(void) splitViewController: (UISplitViewController*)svc willShowViewController:(UIViewController *)aViewController
|
|
158 |
invalidatingBarButtonItem:(UIBarButtonItem *)barButtonItem {
|
|
159 |
/*UIToolbar *toolbar = self.parentViewController.navigationController.toolbar;
|
3316
|
160 |
|
3490
|
161 |
NSMutableArray *items = [[toolbar items] mutableCopy];
|
|
162 |
[items removeObjectAtIndex:0];
|
|
163 |
|
|
164 |
[toolbar setItems:items animated:YES];
|
|
165 |
|
|
166 |
[items release];
|
|
167 |
|
|
168 |
self.popoverController = nil;*/
|
|
169 |
self.navigationItem.rightBarButtonItem = nil;
|
|
170 |
|
3305
|
171 |
}
|
|
172 |
|
3356
|
173 |
|
|
174 |
-(void) didReceiveMemoryWarning {
|
|
175 |
// Releases the view if it doesn't have a superview.
|
|
176 |
[super didReceiveMemoryWarning];
|
|
177 |
// Release any cached data, images, etc that aren't in use.
|
3490
|
178 |
if (generalSettingsViewController.view.superview == nil)
|
|
179 |
generalSettingsViewController = nil;
|
|
180 |
if (teamSettingsViewController.view.superview == nil)
|
|
181 |
teamSettingsViewController = nil;
|
|
182 |
if (weaponSettingsViewController.view.superview == nil)
|
|
183 |
weaponSettingsViewController = nil;
|
|
184 |
if (schemeSettingsViewController.view.superview == nil)
|
|
185 |
schemeSettingsViewController = nil;
|
3487
|
186 |
MSG_MEMCLEAN();
|
3356
|
187 |
}
|
|
188 |
|
|
189 |
-(void) viewDidUnload {
|
|
190 |
self.controllerNames = nil;
|
|
191 |
generalSettingsViewController = nil;
|
|
192 |
teamSettingsViewController = nil;
|
|
193 |
weaponSettingsViewController = nil;
|
|
194 |
schemeSettingsViewController = nil;
|
|
195 |
[super viewDidUnload];
|
3490
|
196 |
MSG_DIDUNLOAD();
|
3356
|
197 |
}
|
|
198 |
|
|
199 |
-(void) dealloc {
|
|
200 |
[controllerNames release];
|
|
201 |
[generalSettingsViewController release];
|
|
202 |
[teamSettingsViewController release];
|
|
203 |
[weaponSettingsViewController release];
|
|
204 |
[schemeSettingsViewController release];
|
|
205 |
[super dealloc];
|
|
206 |
}
|
3305
|
207 |
@end
|