author | koda |
Thu, 17 Jun 2010 20:30:39 +0200 | |
changeset 3514 | 59dbd31e9953 |
parent 3513 | cocoaTouch/DetailViewController.m@f589230fa21b |
child 3535 | 9e78c1f3d8d8 |
permissions | -rw-r--r-- |
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 |
|
3490 | 18 |
@synthesize controllerNames,popoverController; |
3305 | 19 |
|
20 |
||
3335 | 21 |
-(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation { |
22 |
return rotationManager(interfaceOrientation); |
|
23 |
} |
|
24 |
||
3490 | 25 |
-(void) willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration{ |
26 |
self.view.frame = CGRectMake(0, 0, 1024, 1024); |
|
27 |
} |
|
28 |
||
3357 | 29 |
-(void) viewDidLoad { |
3305 | 30 |
self.title = NSLocalizedString(@"Settings",@""); |
31 |
||
3316 | 32 |
// allocate controllers and store them into the array |
3356 | 33 |
NSArray *array= [[NSArray alloc] initWithObjects:NSLocalizedString(@"General",@""), |
34 |
NSLocalizedString(@"Teams",@""), |
|
35 |
NSLocalizedString(@"Weapons",@""), |
|
36 |
NSLocalizedString(@"Schemes",@""), |
|
37 |
nil]; |
|
38 |
self.controllerNames = array; |
|
3305 | 39 |
[array release]; |
3316 | 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) { |
|
3356 | 43 |
|
3357 | 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 |
||
3356 | 51 |
//[self.navigationController pushViewController:nextController animated:NO]; |
3316 | 52 |
} else { |
3356 | 53 |
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone |
54 |
target:self |
|
55 |
action:@selector(dismissSplitView)]; |
|
3316 | 56 |
} |
57 |
||
3305 | 58 |
[super viewDidLoad]; |
59 |
} |
|
60 |
||
61 |
||
62 |
#pragma mark - |
|
63 |
#pragma mark Table view data source |
|
64 |
-(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView { |
|
3357 | 65 |
// don't display |
66 |
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) |
|
67 |
return 0; |
|
68 |
else |
|
69 |
return 1; |
|
3305 | 70 |
} |
71 |
||
72 |
-(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { |
|
3356 | 73 |
return [controllerNames count]; |
3305 | 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 |
||
3356 | 87 |
cell.textLabel.text = [controllerNames objectAtIndex:row]; |
3305 | 88 |
cell.imageView.image = [UIImage imageNamed:@"Icon.png"]; |
89 |
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; |
|
90 |
||
91 |
return cell; |
|
92 |
} |
|
93 |
||
3357 | 94 |
#pragma mark - |
95 |
#pragma mark Table view delegate |
|
3305 | 96 |
-(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { |
97 |
NSInteger row = [indexPath row]; |
|
3364 | 98 |
UIViewController *nextController = nil; |
3356 | 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]; |
|
3305 | 124 |
[self.navigationController pushViewController:nextController animated:YES]; |
125 |
} |
|
126 |
||
3490 | 127 |
-(IBAction) dismissSplitView { |
128 |
[[NSNotificationCenter defaultCenter] postNotificationName:@"dismissModalView" object:nil]; |
|
3305 | 129 |
} |
130 |
||
3513
f589230fa21b
now it's possible to select the scheme file in the ifrontendfix a type about loading an image (iphone file system IS case senstive)
koda
parents:
3490
diff
changeset
|
131 |
#if __IPHONE_3_2 |
3305 | 132 |
#pragma mark - |
3490 | 133 |
#pragma mark splitview support |
134 |
-(void) splitViewController:(UISplitViewController *)svc popoverController:(UIPopoverController *)pc willPresentViewController:(UIViewController *)aViewController { |
|
135 |
if (popoverController != nil) { |
|
136 |
[popoverController dismissPopoverAnimated:YES]; |
|
137 |
} |
|
3305 | 138 |
} |
139 |
||
3490 | 140 |
// Called when the master view controller is about to be hidden |
141 |
-(void) splitViewController: (UISplitViewController*)svc willHideViewController:(UIViewController *)aViewController |
|
142 |
withBarButtonItem:(UIBarButtonItem*)barButtonItem forPopoverController: (UIPopoverController*)pc { |
|
143 |
||
144 |
/* barButtonItem.title = @"Master View"; |
|
145 |
UIToolbar *toolbar = self.parentViewController.navigationController.toolbar; |
|
146 |
NSMutableArray *items = [[toolbar items] mutableCopy]; |
|
147 |
[items insertObject:barButtonItem atIndex:0]; |
|
148 |
[toolbar setItems:items animated:YES]; |
|
149 |
||
150 |
[items release]; |
|
151 |
||
152 |
self.popoverController = pc;*/ |
|
153 |
barButtonItem.title = aViewController.title; |
|
154 |
self.navigationItem.rightBarButtonItem = barButtonItem; |
|
3305 | 155 |
} |
3490 | 156 |
|
157 |
// Called when the master view controller is about to appear |
|
158 |
-(void) splitViewController: (UISplitViewController*)svc willShowViewController:(UIViewController *)aViewController |
|
159 |
invalidatingBarButtonItem:(UIBarButtonItem *)barButtonItem { |
|
160 |
/*UIToolbar *toolbar = self.parentViewController.navigationController.toolbar; |
|
3316 | 161 |
|
3490 | 162 |
NSMutableArray *items = [[toolbar items] mutableCopy]; |
163 |
[items removeObjectAtIndex:0]; |
|
164 |
||
165 |
[toolbar setItems:items animated:YES]; |
|
166 |
||
167 |
[items release]; |
|
168 |
||
169 |
self.popoverController = nil;*/ |
|
170 |
self.navigationItem.rightBarButtonItem = nil; |
|
171 |
||
3305 | 172 |
} |
3513
f589230fa21b
now it's possible to select the scheme file in the ifrontendfix a type about loading an image (iphone file system IS case senstive)
koda
parents:
3490
diff
changeset
|
173 |
#endif |
3356 | 174 |
|
175 |
-(void) didReceiveMemoryWarning { |
|
176 |
// Releases the view if it doesn't have a superview. |
|
177 |
[super didReceiveMemoryWarning]; |
|
178 |
// Release any cached data, images, etc that aren't in use. |
|
3490 | 179 |
if (generalSettingsViewController.view.superview == nil) |
180 |
generalSettingsViewController = nil; |
|
181 |
if (teamSettingsViewController.view.superview == nil) |
|
182 |
teamSettingsViewController = nil; |
|
183 |
if (weaponSettingsViewController.view.superview == nil) |
|
184 |
weaponSettingsViewController = nil; |
|
185 |
if (schemeSettingsViewController.view.superview == nil) |
|
186 |
schemeSettingsViewController = nil; |
|
3487 | 187 |
MSG_MEMCLEAN(); |
3356 | 188 |
} |
189 |
||
190 |
-(void) viewDidUnload { |
|
191 |
self.controllerNames = nil; |
|
192 |
generalSettingsViewController = nil; |
|
193 |
teamSettingsViewController = nil; |
|
194 |
weaponSettingsViewController = nil; |
|
195 |
schemeSettingsViewController = nil; |
|
196 |
[super viewDidUnload]; |
|
3490 | 197 |
MSG_DIDUNLOAD(); |
3356 | 198 |
} |
199 |
||
200 |
-(void) dealloc { |
|
201 |
[controllerNames release]; |
|
202 |
[generalSettingsViewController release]; |
|
203 |
[teamSettingsViewController release]; |
|
204 |
[weaponSettingsViewController release]; |
|
205 |
[schemeSettingsViewController release]; |
|
206 |
[super dealloc]; |
|
207 |
} |
|
3305 | 208 |
@end |