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 |
}
|
3356
|
172 |
|
|
173 |
-(void) didReceiveMemoryWarning {
|
|
174 |
// Releases the view if it doesn't have a superview.
|
|
175 |
[super didReceiveMemoryWarning];
|
|
176 |
// Release any cached data, images, etc that aren't in use.
|
3490
|
177 |
if (generalSettingsViewController.view.superview == nil)
|
|
178 |
generalSettingsViewController = nil;
|
|
179 |
if (teamSettingsViewController.view.superview == nil)
|
|
180 |
teamSettingsViewController = nil;
|
|
181 |
if (weaponSettingsViewController.view.superview == nil)
|
|
182 |
weaponSettingsViewController = nil;
|
|
183 |
if (schemeSettingsViewController.view.superview == nil)
|
|
184 |
schemeSettingsViewController = nil;
|
3487
|
185 |
MSG_MEMCLEAN();
|
3356
|
186 |
}
|
|
187 |
|
|
188 |
-(void) viewDidUnload {
|
|
189 |
self.controllerNames = nil;
|
|
190 |
generalSettingsViewController = nil;
|
|
191 |
teamSettingsViewController = nil;
|
|
192 |
weaponSettingsViewController = nil;
|
|
193 |
schemeSettingsViewController = nil;
|
|
194 |
[super viewDidUnload];
|
3490
|
195 |
MSG_DIDUNLOAD();
|
3356
|
196 |
}
|
|
197 |
|
|
198 |
-(void) dealloc {
|
|
199 |
[controllerNames release];
|
|
200 |
[generalSettingsViewController release];
|
|
201 |
[teamSettingsViewController release];
|
|
202 |
[weaponSettingsViewController release];
|
|
203 |
[schemeSettingsViewController release];
|
|
204 |
[super dealloc];
|
|
205 |
}
|
3305
|
206 |
@end
|