author | koda |
Mon, 02 Aug 2010 00:55:24 +0200 | |
changeset 3703 | 12d17c6e8855 |
parent 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 |
|
3701 | 18 |
@synthesize controllerNames, popoverController; |
3547 | 19 |
|
20 |
||
21 |
-(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation { |
|
22 |
return rotationManager(interfaceOrientation); |
|
23 |
} |
|
24 |
||
25 |
-(void) viewDidLoad { |
|
26 |
self.title = NSLocalizedString(@"Settings",@""); |
|
27 |
||
28 |
// allocate controllers and store them into the array |
|
3697 | 29 |
NSArray *array= [[NSArray alloc] initWithObjects:NSLocalizedString(@"General",@""), |
3547 | 30 |
NSLocalizedString(@"Teams",@""), |
31 |
NSLocalizedString(@"Weapons",@""), |
|
32 |
NSLocalizedString(@"Schemes",@""), |
|
33 |
nil]; |
|
34 |
self.controllerNames = array; |
|
35 |
[array release]; |
|
3697 | 36 |
|
3547 | 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) { |
|
3697 | 39 |
|
3547 | 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]; |
|
3697 | 46 |
|
3547 | 47 |
//[self.navigationController pushViewController:nextController animated:NO]; |
48 |
} else { |
|
49 |
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone |
|
50 |
target:self |
|
51 |
action:@selector(dismissSplitView)]; |
|
52 |
} |
|
53 |
||
54 |
[super viewDidLoad]; |
|
55 |
} |
|
56 |
||
57 |
||
58 |
#pragma mark - |
|
59 |
#pragma mark Table view data source |
|
60 |
-(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView { |
|
3697 | 61 |
// don't display |
3547 | 62 |
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) |
63 |
return 0; |
|
64 |
else |
|
65 |
return 1; |
|
66 |
} |
|
67 |
||
68 |
-(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { |
|
69 |
return [controllerNames count]; |
|
70 |
} |
|
71 |
||
72 |
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { |
|
73 |
static NSString *CellIdentifier = @"Cell"; |
|
3697 | 74 |
|
3547 | 75 |
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; |
76 |
if (cell == nil) { |
|
3697 | 77 |
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault |
3547 | 78 |
reuseIdentifier:CellIdentifier] autorelease]; |
79 |
} |
|
3697 | 80 |
|
3547 | 81 |
NSInteger row = [indexPath row]; |
3697 | 82 |
|
3547 | 83 |
cell.textLabel.text = [controllerNames objectAtIndex:row]; |
84 |
cell.imageView.image = [UIImage imageNamed:@"Icon.png"]; |
|
85 |
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; |
|
3697 | 86 |
|
3547 | 87 |
return cell; |
88 |
} |
|
89 |
||
90 |
#pragma mark - |
|
91 |
#pragma mark Table view delegate |
|
92 |
-(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { |
|
93 |
NSInteger row = [indexPath row]; |
|
94 |
UIViewController *nextController = nil; |
|
3697 | 95 |
|
3547 | 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 |
} |
|
3697 | 118 |
|
3547 | 119 |
nextController.title = [controllerNames objectAtIndex:row]; |
120 |
[self.navigationController pushViewController:nextController animated:YES]; |
|
121 |
} |
|
122 |
||
123 |
-(IBAction) dismissSplitView { |
|
124 |
[[NSNotificationCenter defaultCenter] postNotificationName:@"dismissModalView" object:nil]; |
|
125 |
} |
|
126 |
||
127 |
#pragma mark - |
|
128 |
#pragma mark splitview support |
|
129 |
-(void) splitViewController:(UISplitViewController *)svc popoverController:(UIPopoverController *)pc willPresentViewController:(UIViewController *)aViewController { |
|
130 |
if (popoverController != nil) { |
|
131 |
[popoverController dismissPopoverAnimated:YES]; |
|
132 |
} |
|
133 |
} |
|
134 |
||
135 |
// Called when the master view controller is about to be hidden |
|
3697 | 136 |
-(void) splitViewController: (UISplitViewController*)svc willHideViewController:(UIViewController *)aViewController |
3547 | 137 |
withBarButtonItem:(UIBarButtonItem*)barButtonItem forPopoverController: (UIPopoverController*)pc { |
138 |
||
139 |
/* barButtonItem.title = @"Master View"; |
|
140 |
UIToolbar *toolbar = self.parentViewController.navigationController.toolbar; |
|
141 |
NSMutableArray *items = [[toolbar items] mutableCopy]; |
|
142 |
[items insertObject:barButtonItem atIndex:0]; |
|
143 |
[toolbar setItems:items animated:YES]; |
|
144 |
||
145 |
[items release]; |
|
146 |
||
147 |
self.popoverController = pc;*/ |
|
148 |
barButtonItem.title = aViewController.title; |
|
149 |
self.navigationItem.rightBarButtonItem = barButtonItem; |
|
150 |
} |
|
151 |
||
152 |
// Called when the master view controller is about to appear |
|
3697 | 153 |
-(void) splitViewController: (UISplitViewController*)svc willShowViewController:(UIViewController *)aViewController |
3547 | 154 |
invalidatingBarButtonItem:(UIBarButtonItem *)barButtonItem { |
155 |
/*UIToolbar *toolbar = self.parentViewController.navigationController.toolbar; |
|
156 |
||
157 |
NSMutableArray *items = [[toolbar items] mutableCopy]; |
|
158 |
[items removeObjectAtIndex:0]; |
|
159 |
||
160 |
[toolbar setItems:items animated:YES]; |
|
161 |
||
162 |
[items release]; |
|
163 |
||
164 |
self.popoverController = nil;*/ |
|
165 |
self.navigationItem.rightBarButtonItem = nil; |
|
166 |
||
167 |
} |
|
168 |
||
169 |
-(void) didReceiveMemoryWarning { |
|
170 |
// Releases the view if it doesn't have a superview. |
|
171 |
[super didReceiveMemoryWarning]; |
|
172 |
// Release any cached data, images, etc that aren't in use. |
|
173 |
if (generalSettingsViewController.view.superview == nil) |
|
174 |
generalSettingsViewController = nil; |
|
175 |
if (teamSettingsViewController.view.superview == nil) |
|
176 |
teamSettingsViewController = nil; |
|
177 |
if (weaponSettingsViewController.view.superview == nil) |
|
178 |
weaponSettingsViewController = nil; |
|
179 |
if (schemeSettingsViewController.view.superview == nil) |
|
180 |
schemeSettingsViewController = nil; |
|
181 |
MSG_MEMCLEAN(); |
|
182 |
} |
|
183 |
||
184 |
-(void) viewDidUnload { |
|
185 |
self.controllerNames = nil; |
|
186 |
generalSettingsViewController = nil; |
|
187 |
teamSettingsViewController = nil; |
|
188 |
weaponSettingsViewController = nil; |
|
189 |
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
|
190 |
MSG_DIDUNLOAD(); |
3547 | 191 |
[super viewDidUnload]; |
192 |
} |
|
193 |
||
194 |
-(void) dealloc { |
|
195 |
[controllerNames release]; |
|
196 |
[generalSettingsViewController release]; |
|
197 |
[teamSettingsViewController release]; |
|
198 |
[weaponSettingsViewController release]; |
|
199 |
[schemeSettingsViewController release]; |
|
200 |
[super dealloc]; |
|
201 |
} |
|
202 |
@end |