author | koda |
Sun, 01 Aug 2010 17:58:09 +0200 | |
changeset 3701 | 8c449776ebe6 |
parent 3697 | d5b30d6373fc |
child 3737 | 2ba6ac8a114b |
permissions | -rw-r--r-- |
3547 | 1 |
// |
2 |
// MasterViewController.m |
|
3 |
// HedgewarsMobile |
|
4 |
// |
|
5 |
// Created by Vittorio on 27/03/10. |
|
6 |
// Copyright 2010 __MyCompanyName__. All rights reserved. |
|
7 |
// |
|
8 |
||
9 |
#import "MasterViewController.h" |
|
10 |
#import "DetailViewController.h" |
|
11 |
#import "GeneralSettingsViewController.h" |
|
12 |
#import "TeamSettingsViewController.h" |
|
13 |
#import "WeaponSettingsViewController.h" |
|
14 |
#import "SchemeSettingsViewController.h" |
|
15 |
#import "CommodityFunctions.h" |
|
16 |
||
17 |
@implementation MasterViewController |
|
3701 | 18 |
@synthesize targetController, controllerNames, lastIndexPath; |
3547 | 19 |
|
20 |
||
21 |
-(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation { |
|
22 |
return rotationManager(interfaceOrientation); |
|
23 |
} |
|
24 |
||
25 |
||
26 |
#pragma mark - |
|
27 |
#pragma mark View lifecycle |
|
28 |
-(void) viewDidLoad { |
|
29 |
[super viewDidLoad]; |
|
3697 | 30 |
|
3547 | 31 |
// the list of selectable controllers |
3701 | 32 |
NSArray *array = [[NSArray alloc] initWithObjects:NSLocalizedString(@"General",@""), |
33 |
NSLocalizedString(@"Teams",@""), |
|
34 |
NSLocalizedString(@"Weapons",@""), |
|
35 |
NSLocalizedString(@"Schemes",@""), |
|
36 |
nil]; |
|
37 |
self.controllerNames = array; |
|
38 |
[array release]; |
|
39 |
||
40 |
// targetControllers tells whether we're on the right or left side of the splitview -- on iphone we only use the right side |
|
41 |
if (targetController == nil && UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { |
|
42 |
if (nil == generalSettingsViewController) |
|
43 |
generalSettingsViewController = [[GeneralSettingsViewController alloc] initWithStyle:UITableViewStyleGrouped]; |
|
44 |
generalSettingsViewController.navigationItem.hidesBackButton = YES; |
|
45 |
[self.navigationController pushViewController:generalSettingsViewController animated:NO]; |
|
46 |
} else { |
|
47 |
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone |
|
48 |
target:self |
|
49 |
action:@selector(dismissSplitView)]; |
|
50 |
} |
|
3547 | 51 |
} |
52 |
||
53 |
#pragma mark - |
|
54 |
#pragma mark Table view data source |
|
55 |
-(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView { |
|
56 |
return 1; |
|
57 |
} |
|
58 |
||
59 |
-(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { |
|
60 |
return [controllerNames count]; |
|
61 |
} |
|
62 |
||
63 |
// Customize the appearance of table view cells. |
|
64 |
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { |
|
65 |
static NSString *CellIdentifier = @"Cell"; |
|
3697 | 66 |
|
3547 | 67 |
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; |
68 |
if (cell == nil) { |
|
69 |
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; |
|
70 |
} |
|
3697 | 71 |
|
3701 | 72 |
cell.textLabel.text = [controllerNames objectAtIndex:[indexPath row]]; |
73 |
if (nil == targetController) { |
|
74 |
UIImage *icon = [[UIImage alloc] initWithContentsOfFile:@"Icon-Small.png"]; |
|
75 |
cell.imageView.image = icon; |
|
76 |
[icon release]; |
|
77 |
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; |
|
78 |
} else |
|
79 |
cell.accessoryType = UITableViewCellAccessoryNone; |
|
80 |
||
3547 | 81 |
return cell; |
82 |
} |
|
83 |
||
84 |
#pragma mark - |
|
85 |
#pragma mark Table view delegate |
|
86 |
-(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { |
|
87 |
int newRow = [indexPath row]; |
|
88 |
int oldRow = (lastIndexPath != nil) ? [lastIndexPath row] : -1; |
|
89 |
UIViewController *nextController = nil; |
|
3697 | 90 |
|
3547 | 91 |
if (newRow != oldRow) { |
92 |
[self.tableView deselectRowAtIndexPath:lastIndexPath animated:YES]; |
|
3701 | 93 |
[targetController.navigationController popToRootViewControllerAnimated:NO]; |
3697 | 94 |
|
3547 | 95 |
switch (newRow) { |
96 |
case 0: |
|
97 |
if (nil == generalSettingsViewController) |
|
98 |
generalSettingsViewController = [[GeneralSettingsViewController alloc] initWithStyle:UITableViewStyleGrouped]; |
|
99 |
nextController = generalSettingsViewController; |
|
100 |
break; |
|
101 |
case 1: |
|
102 |
if (nil == teamSettingsViewController) |
|
103 |
teamSettingsViewController = [[TeamSettingsViewController alloc] initWithStyle:UITableViewStyleGrouped]; |
|
104 |
nextController = teamSettingsViewController; |
|
105 |
break; |
|
106 |
case 2: |
|
107 |
if (nil == weaponSettingsViewController) |
|
108 |
weaponSettingsViewController = [[WeaponSettingsViewController alloc] initWithStyle:UITableViewStyleGrouped]; |
|
109 |
nextController = weaponSettingsViewController; |
|
110 |
break; |
|
111 |
case 3: |
|
112 |
if (nil == schemeSettingsViewController) |
|
113 |
schemeSettingsViewController = [[SchemeSettingsViewController alloc] initWithStyle:UITableViewStyleGrouped]; |
|
114 |
nextController = schemeSettingsViewController; |
|
115 |
break; |
|
116 |
} |
|
3697 | 117 |
|
3547 | 118 |
nextController.title = [controllerNames objectAtIndex:newRow]; |
119 |
self.lastIndexPath = indexPath; |
|
120 |
[self.tableView selectRowAtIndexPath:indexPath animated:YES scrollPosition:UITableViewScrollPositionNone]; |
|
3701 | 121 |
|
122 |
if (nil == targetController) { |
|
123 |
nextController.navigationItem.hidesBackButton = NO; |
|
124 |
[self.navigationController pushViewController:nextController animated:YES]; |
|
125 |
} else { |
|
126 |
nextController.navigationItem.hidesBackButton = YES; |
|
127 |
[targetController.navigationController pushViewController:nextController animated:NO]; |
|
128 |
} |
|
3547 | 129 |
} |
130 |
} |
|
131 |
||
132 |
||
133 |
#pragma mark - |
|
134 |
#pragma mark Memory management |
|
135 |
-(void) didReceiveMemoryWarning { |
|
136 |
// Releases the view if it doesn't have a superview. |
|
137 |
[super didReceiveMemoryWarning]; |
|
3697 | 138 |
// Relinquish ownership any cached data, images, etc that aren't in use. |
3547 | 139 |
if (generalSettingsViewController.view.superview == nil) |
140 |
generalSettingsViewController = nil; |
|
141 |
if (teamSettingsViewController.view.superview == nil) |
|
142 |
teamSettingsViewController = nil; |
|
143 |
if (weaponSettingsViewController.view.superview == nil) |
|
144 |
weaponSettingsViewController = nil; |
|
145 |
if (schemeSettingsViewController.view.superview == nil) |
|
146 |
schemeSettingsViewController = nil; |
|
147 |
MSG_MEMCLEAN(); |
|
148 |
} |
|
149 |
||
150 |
-(void) viewDidUnload { |
|
3701 | 151 |
self.targetController = nil; |
3547 | 152 |
self.controllerNames = nil; |
153 |
self.lastIndexPath = nil; |
|
154 |
generalSettingsViewController = nil; |
|
155 |
teamSettingsViewController = nil; |
|
156 |
weaponSettingsViewController = nil; |
|
157 |
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
|
158 |
MSG_DIDUNLOAD(); |
3547 | 159 |
[super viewDidUnload]; |
160 |
} |
|
161 |
||
162 |
-(void) dealloc { |
|
3701 | 163 |
targetController = nil; |
3547 | 164 |
[controllerNames release]; |
165 |
[lastIndexPath release]; |
|
166 |
[generalSettingsViewController release]; |
|
167 |
[teamSettingsViewController release]; |
|
168 |
[weaponSettingsViewController release]; |
|
169 |
[schemeSettingsViewController release]; |
|
170 |
[super dealloc]; |
|
171 |
} |
|
172 |
||
173 |
-(IBAction) dismissSplitView { |
|
174 |
[[NSNotificationCenter defaultCenter] postNotificationName:@"dismissModalView" object:nil]; |
|
175 |
} |
|
176 |
||
177 |
@end |
|
178 |