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" |
|
10 #import "SDL_uikitappdelegate.h" |
|
11 #import "GeneralSettingsViewController.h" |
|
12 #import "TeamSettingsViewController.h" |
|
13 #import "WeaponSettingsViewController.h" |
|
14 #import "SchemeSettingsViewController.h" |
|
15 #import "CommodityFunctions.h" |
|
16 |
|
17 @implementation DetailViewController |
|
18 @synthesize controllerNames,popoverController; |
|
19 |
|
20 |
|
21 -(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation { |
|
22 return rotationManager(interfaceOrientation); |
|
23 } |
|
24 |
|
25 -(void) willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration{ |
|
26 self.view.frame = CGRectMake(0, 0, 1024, 1024); |
|
27 } |
|
28 |
|
29 -(void) viewDidLoad { |
|
30 self.title = NSLocalizedString(@"Settings",@""); |
|
31 |
|
32 // allocate controllers and store them into the array |
|
33 NSArray *array= [[NSArray alloc] initWithObjects:NSLocalizedString(@"General",@""), |
|
34 NSLocalizedString(@"Teams",@""), |
|
35 NSLocalizedString(@"Weapons",@""), |
|
36 NSLocalizedString(@"Schemes",@""), |
|
37 nil]; |
|
38 self.controllerNames = array; |
|
39 [array release]; |
|
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) { |
|
43 |
|
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 |
|
51 //[self.navigationController pushViewController:nextController animated:NO]; |
|
52 } else { |
|
53 self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone |
|
54 target:self |
|
55 action:@selector(dismissSplitView)]; |
|
56 } |
|
57 |
|
58 [super viewDidLoad]; |
|
59 } |
|
60 |
|
61 |
|
62 #pragma mark - |
|
63 #pragma mark Table view data source |
|
64 -(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView { |
|
65 // don't display |
|
66 if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) |
|
67 return 0; |
|
68 else |
|
69 return 1; |
|
70 } |
|
71 |
|
72 -(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { |
|
73 return [controllerNames count]; |
|
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 |
|
87 cell.textLabel.text = [controllerNames objectAtIndex:row]; |
|
88 cell.imageView.image = [UIImage imageNamed:@"Icon.png"]; |
|
89 cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; |
|
90 |
|
91 return cell; |
|
92 } |
|
93 |
|
94 #pragma mark - |
|
95 #pragma mark Table view delegate |
|
96 -(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { |
|
97 NSInteger row = [indexPath row]; |
|
98 UIViewController *nextController = nil; |
|
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]; |
|
124 [self.navigationController pushViewController:nextController animated:YES]; |
|
125 } |
|
126 |
|
127 -(IBAction) dismissSplitView { |
|
128 [[NSNotificationCenter defaultCenter] postNotificationName:@"dismissModalView" object:nil]; |
|
129 } |
|
130 |
|
131 #pragma mark - |
|
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 } |
|
137 } |
|
138 |
|
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; |
|
154 } |
|
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; |
|
160 |
|
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 |
|
171 } |
|
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. |
|
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; |
|
185 MSG_MEMCLEAN(); |
|
186 } |
|
187 |
|
188 -(void) viewDidUnload { |
|
189 self.controllerNames = nil; |
|
190 generalSettingsViewController = nil; |
|
191 teamSettingsViewController = nil; |
|
192 weaponSettingsViewController = nil; |
|
193 schemeSettingsViewController = nil; |
|
194 MSG_DIDUNLOAD(); |
|
195 [super viewDidUnload]; |
|
196 } |
|
197 |
|
198 -(void) dealloc { |
|
199 [controllerNames release]; |
|
200 [generalSettingsViewController release]; |
|
201 [teamSettingsViewController release]; |
|
202 [weaponSettingsViewController release]; |
|
203 [schemeSettingsViewController release]; |
|
204 [super dealloc]; |
|
205 } |
|
206 @end |
|