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