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 |
// 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 |
|
18 |
@synthesize detailViewController, controllerNames, lastIndexPath; |
|
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 |
32 |
controllerNames = [[NSArray alloc] initWithObjects:NSLocalizedString(@"General",@""), |
|
33 |
NSLocalizedString(@"Teams",@""), |
|
34 |
NSLocalizedString(@"Weapons",@""), |
|
35 |
NSLocalizedString(@"Schemes",@""), |
|
36 |
nil]; |
|
37 |
// the "Done" button on top left |
|
38 |
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone |
|
39 |
target:self |
|
40 |
action:@selector(dismissSplitView)]; |
|
41 |
} |
|
42 |
||
43 |
#pragma mark - |
|
44 |
#pragma mark Table view data source |
|
45 |
||
46 |
-(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView { |
|
47 |
return 1; |
|
48 |
} |
|
49 |
||
50 |
-(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { |
|
51 |
return [controllerNames count]; |
|
52 |
} |
|
53 |
||
54 |
// Customize the appearance of table view cells. |
|
55 |
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { |
|
56 |
static NSString *CellIdentifier = @"Cell"; |
|
3697 | 57 |
|
3547 | 58 |
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; |
59 |
if (cell == nil) { |
|
60 |
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; |
|
61 |
cell.textLabel.text = [controllerNames objectAtIndex:[indexPath row]]; |
|
62 |
} |
|
3697 | 63 |
|
3547 | 64 |
return cell; |
65 |
} |
|
66 |
||
67 |
#pragma mark - |
|
68 |
#pragma mark Table view delegate |
|
69 |
-(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { |
|
70 |
int newRow = [indexPath row]; |
|
71 |
int oldRow = (lastIndexPath != nil) ? [lastIndexPath row] : -1; |
|
72 |
UIViewController *nextController = nil; |
|
3697 | 73 |
|
3547 | 74 |
if (newRow != oldRow) { |
75 |
[self.tableView deselectRowAtIndexPath:lastIndexPath animated:YES]; |
|
76 |
[detailViewController.navigationController popToRootViewControllerAnimated:NO]; |
|
3697 | 77 |
|
3547 | 78 |
switch (newRow) { |
79 |
case 0: |
|
80 |
if (nil == generalSettingsViewController) |
|
81 |
generalSettingsViewController = [[GeneralSettingsViewController alloc] initWithStyle:UITableViewStyleGrouped]; |
|
82 |
nextController = generalSettingsViewController; |
|
83 |
break; |
|
84 |
case 1: |
|
85 |
if (nil == teamSettingsViewController) |
|
86 |
teamSettingsViewController = [[TeamSettingsViewController alloc] initWithStyle:UITableViewStyleGrouped]; |
|
87 |
nextController = teamSettingsViewController; |
|
88 |
break; |
|
89 |
case 2: |
|
90 |
if (nil == weaponSettingsViewController) |
|
91 |
weaponSettingsViewController = [[WeaponSettingsViewController alloc] initWithStyle:UITableViewStyleGrouped]; |
|
92 |
nextController = weaponSettingsViewController; |
|
93 |
break; |
|
94 |
case 3: |
|
95 |
if (nil == schemeSettingsViewController) |
|
96 |
schemeSettingsViewController = [[SchemeSettingsViewController alloc] initWithStyle:UITableViewStyleGrouped]; |
|
97 |
nextController = schemeSettingsViewController; |
|
98 |
break; |
|
99 |
} |
|
3697 | 100 |
|
3547 | 101 |
nextController.navigationItem.hidesBackButton = YES; |
102 |
nextController.title = [controllerNames objectAtIndex:newRow]; |
|
103 |
[detailViewController.navigationController pushViewController:nextController animated:NO]; |
|
104 |
self.lastIndexPath = indexPath; |
|
105 |
[self.tableView selectRowAtIndexPath:indexPath animated:YES scrollPosition:UITableViewScrollPositionNone]; |
|
106 |
} |
|
107 |
} |
|
108 |
||
109 |
||
110 |
#pragma mark - |
|
111 |
#pragma mark Memory management |
|
112 |
-(void) didReceiveMemoryWarning { |
|
113 |
// Releases the view if it doesn't have a superview. |
|
114 |
[super didReceiveMemoryWarning]; |
|
3697 | 115 |
// Relinquish ownership any cached data, images, etc that aren't in use. |
3547 | 116 |
if (generalSettingsViewController.view.superview == nil) |
117 |
generalSettingsViewController = nil; |
|
118 |
if (teamSettingsViewController.view.superview == nil) |
|
119 |
teamSettingsViewController = nil; |
|
120 |
if (weaponSettingsViewController.view.superview == nil) |
|
121 |
weaponSettingsViewController = nil; |
|
122 |
if (schemeSettingsViewController.view.superview == nil) |
|
123 |
schemeSettingsViewController = nil; |
|
124 |
MSG_MEMCLEAN(); |
|
125 |
} |
|
126 |
||
127 |
-(void) viewDidUnload { |
|
128 |
self.detailViewController = nil; |
|
129 |
self.controllerNames = nil; |
|
130 |
self.lastIndexPath = nil; |
|
131 |
generalSettingsViewController = nil; |
|
132 |
teamSettingsViewController = nil; |
|
133 |
weaponSettingsViewController = nil; |
|
134 |
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
|
135 |
MSG_DIDUNLOAD(); |
3547 | 136 |
[super viewDidUnload]; |
137 |
} |
|
138 |
||
139 |
-(void) dealloc { |
|
140 |
[controllerNames release]; |
|
141 |
[detailViewController release]; |
|
142 |
[lastIndexPath release]; |
|
143 |
[generalSettingsViewController release]; |
|
144 |
[teamSettingsViewController release]; |
|
145 |
[weaponSettingsViewController release]; |
|
146 |
[schemeSettingsViewController release]; |
|
147 |
[super dealloc]; |
|
148 |
} |
|
149 |
||
150 |
-(IBAction) dismissSplitView { |
|
151 |
[[NSNotificationCenter defaultCenter] postNotificationName:@"dismissModalView" object:nil]; |
|
152 |
} |
|
153 |
||
154 |
@end |
|
155 |