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
|
3356
|
18 |
@synthesize popoverController, controllerNames;
|
3305
|
19 |
|
|
20 |
|
3335
|
21 |
-(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation {
|
|
22 |
return rotationManager(interfaceOrientation);
|
|
23 |
}
|
|
24 |
|
3357
|
25 |
-(void) viewDidLoad {
|
3305
|
26 |
self.title = NSLocalizedString(@"Settings",@"");
|
|
27 |
|
3316
|
28 |
// allocate controllers and store them into the array
|
3356
|
29 |
NSArray *array= [[NSArray alloc] initWithObjects:NSLocalizedString(@"General",@""),
|
|
30 |
NSLocalizedString(@"Teams",@""),
|
|
31 |
NSLocalizedString(@"Weapons",@""),
|
|
32 |
NSLocalizedString(@"Schemes",@""),
|
|
33 |
nil];
|
|
34 |
self.controllerNames = array;
|
3305
|
35 |
[array release];
|
3316
|
36 |
|
|
37 |
// on ipad make the general setting the first view, on iphone add the "Done" button on top left
|
|
38 |
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
|
3356
|
39 |
|
3357
|
40 |
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(112, 112, 480, 320)];
|
|
41 |
label.text = @"Press the buttons on the left";
|
|
42 |
label.font = [UIFont systemFontOfSize:20];
|
|
43 |
label.textAlignment = UITextAlignmentCenter;
|
|
44 |
[self.view addSubview:label];
|
|
45 |
[label release];
|
|
46 |
|
3356
|
47 |
|
|
48 |
//[self.navigationController pushViewController:nextController animated:NO];
|
3316
|
49 |
} else {
|
3356
|
50 |
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone
|
|
51 |
target:self
|
|
52 |
action:@selector(dismissSplitView)];
|
3316
|
53 |
}
|
|
54 |
|
3305
|
55 |
[super viewDidLoad];
|
|
56 |
}
|
|
57 |
|
|
58 |
|
|
59 |
#pragma mark -
|
|
60 |
#pragma mark Table view data source
|
|
61 |
-(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView {
|
3357
|
62 |
// don't display
|
|
63 |
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
|
|
64 |
return 0;
|
|
65 |
else
|
|
66 |
return 1;
|
3305
|
67 |
}
|
|
68 |
|
|
69 |
-(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
|
3356
|
70 |
return [controllerNames count];
|
3305
|
71 |
}
|
|
72 |
|
|
73 |
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
|
|
74 |
static NSString *CellIdentifier = @"Cell";
|
|
75 |
|
|
76 |
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
|
|
77 |
if (cell == nil) {
|
|
78 |
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
|
|
79 |
reuseIdentifier:CellIdentifier] autorelease];
|
|
80 |
}
|
|
81 |
|
|
82 |
NSInteger row = [indexPath row];
|
|
83 |
|
3356
|
84 |
cell.textLabel.text = [controllerNames objectAtIndex:row];
|
3305
|
85 |
cell.imageView.image = [UIImage imageNamed:@"Icon.png"];
|
|
86 |
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
|
|
87 |
|
|
88 |
return cell;
|
|
89 |
}
|
|
90 |
|
3357
|
91 |
#pragma mark -
|
|
92 |
#pragma mark Table view delegate
|
3305
|
93 |
-(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
|
|
94 |
NSInteger row = [indexPath row];
|
3364
|
95 |
UIViewController *nextController = nil;
|
3356
|
96 |
|
|
97 |
switch (row) {
|
|
98 |
case 0:
|
|
99 |
if (nil == generalSettingsViewController)
|
|
100 |
generalSettingsViewController = [[GeneralSettingsViewController alloc] initWithStyle:UITableViewStyleGrouped];
|
|
101 |
nextController = generalSettingsViewController;
|
|
102 |
break;
|
|
103 |
case 1:
|
|
104 |
if (nil == teamSettingsViewController)
|
|
105 |
teamSettingsViewController = [[TeamSettingsViewController alloc] initWithStyle:UITableViewStyleGrouped];
|
|
106 |
nextController = teamSettingsViewController;
|
|
107 |
break;
|
|
108 |
case 2:
|
|
109 |
if (nil == weaponSettingsViewController)
|
|
110 |
weaponSettingsViewController = [[WeaponSettingsViewController alloc] initWithStyle:UITableViewStyleGrouped];
|
|
111 |
nextController = weaponSettingsViewController;
|
|
112 |
break;
|
|
113 |
case 3:
|
|
114 |
if (nil == schemeSettingsViewController)
|
|
115 |
schemeSettingsViewController = [[SchemeSettingsViewController alloc] initWithStyle:UITableViewStyleGrouped];
|
|
116 |
nextController = schemeSettingsViewController;
|
|
117 |
break;
|
|
118 |
}
|
|
119 |
|
|
120 |
nextController.title = [controllerNames objectAtIndex:row];
|
3305
|
121 |
[self.navigationController pushViewController:nextController animated:YES];
|
|
122 |
}
|
|
123 |
|
|
124 |
/*
|
|
125 |
#pragma mark -
|
|
126 |
#pragma mark Managing the popover controller
|
|
127 |
// When setting the detail item, update the view and dismiss the popover controller if it's showing.
|
|
128 |
-(void) setDetailItem:(id) newDetailItem {
|
|
129 |
if (detailItem != newDetailItem) {
|
|
130 |
[detailItem release];
|
|
131 |
detailItem = [newDetailItem retain];
|
|
132 |
|
|
133 |
// Update the view.
|
|
134 |
// navigationBar.topItem.title = (NSString*) detailItem;
|
|
135 |
|
|
136 |
//test.text=(NSString*) detailItem;
|
|
137 |
}
|
|
138 |
|
|
139 |
// if (popoverController != nil) {
|
|
140 |
// [popoverController dismissPopoverAnimated:YES];
|
|
141 |
// }
|
|
142 |
}
|
|
143 |
*/
|
|
144 |
|
|
145 |
#pragma mark -
|
|
146 |
#pragma mark Split view support
|
|
147 |
#ifdef __IPHONE_3_2
|
3335
|
148 |
-(void) splitViewController:(UISplitViewController *)svc willHideViewController:(UIViewController *)aViewController withBarButtonItem:(UIBarButtonItem *)barButtonItem forPopoverController:(UIPopoverController *)pc {
|
3305
|
149 |
barButtonItem.title = @"Master List";
|
3335
|
150 |
[self.navigationController.navigationBar.topItem setLeftBarButtonItem:barButtonItem animated:YES];
|
3305
|
151 |
self.popoverController = pc;
|
|
152 |
}
|
|
153 |
|
|
154 |
// Called when the view is shown again in the split view, invalidating the button and popover controller.
|
|
155 |
-(void) splitViewController: (UISplitViewController*)svc willShowViewController:(UIViewController *)aViewController invalidatingBarButtonItem:(UIBarButtonItem *)barButtonItem {
|
3335
|
156 |
[self.navigationController.navigationBar.topItem setLeftBarButtonItem:nil animated:YES];
|
3305
|
157 |
self.popoverController = nil;
|
|
158 |
}
|
|
159 |
#endif
|
3316
|
160 |
|
3305
|
161 |
-(IBAction) dismissSplitView {
|
|
162 |
[[NSNotificationCenter defaultCenter] postNotificationName:@"dismissModalView" object:nil];
|
|
163 |
}
|
|
164 |
|
3356
|
165 |
|
|
166 |
-(void) didReceiveMemoryWarning {
|
|
167 |
// Releases the view if it doesn't have a superview.
|
|
168 |
[super didReceiveMemoryWarning];
|
|
169 |
// Release any cached data, images, etc that aren't in use.
|
|
170 |
}
|
|
171 |
|
|
172 |
-(void) viewDidUnload {
|
|
173 |
self.controllerNames = nil;
|
|
174 |
self.popoverController = nil;
|
|
175 |
generalSettingsViewController = nil;
|
|
176 |
teamSettingsViewController = nil;
|
|
177 |
weaponSettingsViewController = nil;
|
|
178 |
schemeSettingsViewController = nil;
|
|
179 |
[super viewDidUnload];
|
|
180 |
}
|
|
181 |
|
|
182 |
-(void) dealloc {
|
|
183 |
[controllerNames release];
|
|
184 |
[popoverController release];
|
|
185 |
[generalSettingsViewController release];
|
|
186 |
[teamSettingsViewController release];
|
|
187 |
[weaponSettingsViewController release];
|
|
188 |
[schemeSettingsViewController release];
|
|
189 |
[super dealloc];
|
|
190 |
}
|
3305
|
191 |
@end
|