author | koda |
Sat, 31 Jul 2010 11:24:53 +0200 | |
changeset 3697 | d5b30d6373fc |
parent 3662 | a44406f4369b |
child 3701 | 8c449776ebe6 |
permissions | -rw-r--r-- |
3547 | 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 |
|
3697 | 33 |
NSArray *array= [[NSArray alloc] initWithObjects:NSLocalizedString(@"General",@""), |
3547 | 34 |
NSLocalizedString(@"Teams",@""), |
35 |
NSLocalizedString(@"Weapons",@""), |
|
36 |
NSLocalizedString(@"Schemes",@""), |
|
37 |
nil]; |
|
38 |
self.controllerNames = array; |
|
39 |
[array release]; |
|
3697 | 40 |
|
3547 | 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) { |
|
3697 | 43 |
|
3547 | 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]; |
|
3697 | 50 |
|
3547 | 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 { |
|
3697 | 65 |
// don't display |
3547 | 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"; |
|
3697 | 78 |
|
3547 | 79 |
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; |
80 |
if (cell == nil) { |
|
3697 | 81 |
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault |
3547 | 82 |
reuseIdentifier:CellIdentifier] autorelease]; |
83 |
} |
|
3697 | 84 |
|
3547 | 85 |
NSInteger row = [indexPath row]; |
3697 | 86 |
|
3547 | 87 |
cell.textLabel.text = [controllerNames objectAtIndex:row]; |
88 |
cell.imageView.image = [UIImage imageNamed:@"Icon.png"]; |
|
89 |
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; |
|
3697 | 90 |
|
3547 | 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; |
|
3697 | 99 |
|
3547 | 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 |
} |
|
3697 | 122 |
|
3547 | 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 |
|
3697 | 140 |
-(void) splitViewController: (UISplitViewController*)svc willHideViewController:(UIViewController *)aViewController |
3547 | 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 |
|
3697 | 157 |
-(void) splitViewController: (UISplitViewController*)svc willShowViewController:(UIViewController *)aViewController |
3547 | 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; |
|
3662
a44406f4369b
polish polish polish polish (also: panning horizontal fix, panning momentum, settings page reworked yet again, memory leaks, crashes, segfaults)
koda
parents:
3547
diff
changeset
|
194 |
MSG_DIDUNLOAD(); |
3547 | 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 |