8 |
8 |
9 #import "MasterViewController.h" |
9 #import "MasterViewController.h" |
10 #import "DetailViewController.h" |
10 #import "DetailViewController.h" |
11 #import "GeneralSettingsViewController.h" |
11 #import "GeneralSettingsViewController.h" |
12 #import "TeamSettingsViewController.h" |
12 #import "TeamSettingsViewController.h" |
|
13 #import "WeaponSettingsViewController.h" |
|
14 #import "SchemeSettingsViewController.h" |
13 #import "CommodityFunctions.h" |
15 #import "CommodityFunctions.h" |
14 |
16 |
15 @implementation MasterViewController |
17 @implementation MasterViewController |
16 @synthesize detailViewController, optionList, controllers, lastIndexPath; |
18 @synthesize detailViewController, controllerNames, lastIndexPath; |
17 |
19 |
18 |
20 |
19 -(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation { |
21 -(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation { |
20 return rotationManager(interfaceOrientation); |
22 return rotationManager(interfaceOrientation); |
21 } |
23 } |
25 #pragma mark View lifecycle |
27 #pragma mark View lifecycle |
26 - (void)viewDidLoad { |
28 - (void)viewDidLoad { |
27 [super viewDidLoad]; |
29 [super viewDidLoad]; |
28 |
30 |
29 // the list of selectable controllers |
31 // the list of selectable controllers |
30 optionList = [[NSArray alloc] initWithObjects:NSLocalizedString(@"General",@""), |
32 controllerNames = [[NSArray alloc] initWithObjects:NSLocalizedString(@"General",@""), |
31 NSLocalizedString(@"Teams",@""), |
33 NSLocalizedString(@"Teams",@""), |
32 NSLocalizedString(@"Weapons",@""), |
34 NSLocalizedString(@"Weapons",@""), |
33 NSLocalizedString(@"Schemes",@""), |
35 NSLocalizedString(@"Schemes",@""), |
34 nil]; |
36 nil]; |
35 // the "Done" button on top left |
37 // the "Done" button on top left |
36 self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:0 |
38 self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone |
37 target:self |
39 target:self |
38 action:@selector(dismissSplitView)]; |
40 action:@selector(dismissSplitView)]; |
39 // list of allocated viewcontrollers (same in DetailViewController) |
|
40 NSMutableArray *array= [[NSMutableArray alloc] init]; |
|
41 |
|
42 GeneralSettingsViewController *generalSettingsViewController = [[GeneralSettingsViewController alloc] |
|
43 initWithStyle:UITableViewStyleGrouped]; |
|
44 generalSettingsViewController.title = NSLocalizedString(@"General",@""); |
|
45 generalSettingsViewController.navigationItem.hidesBackButton = YES; |
|
46 [array addObject:generalSettingsViewController]; |
|
47 [generalSettingsViewController release]; |
|
48 |
|
49 TeamSettingsViewController *teamSettingsViewController = [[TeamSettingsViewController alloc] |
|
50 initWithStyle:UITableViewStyleGrouped]; |
|
51 teamSettingsViewController.title = NSLocalizedString(@"Teams",@""); |
|
52 teamSettingsViewController.navigationItem.hidesBackButton = YES; |
|
53 [array addObject:teamSettingsViewController]; |
|
54 [teamSettingsViewController release]; |
|
55 |
|
56 self.controllers = array; |
|
57 [array release]; |
|
58 } |
41 } |
59 |
42 |
60 #pragma mark - |
43 #pragma mark - |
61 #pragma mark Table view data source |
44 #pragma mark Table view data source |
62 |
45 |
63 -(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView { |
46 -(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView { |
64 return 1; |
47 return 1; |
65 } |
48 } |
66 |
49 |
67 |
|
68 -(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { |
50 -(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { |
69 return [optionList count]; |
51 return [controllerNames count]; |
70 } |
52 } |
71 |
|
72 |
53 |
73 // Customize the appearance of table view cells. |
54 // Customize the appearance of table view cells. |
74 -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { |
55 -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { |
75 static NSString *CellIdentifier = @"Cell"; |
56 static NSString *CellIdentifier = @"Cell"; |
76 |
57 |
77 UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; |
58 UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; |
78 if (cell == nil) { |
59 if (cell == nil) { |
79 cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; |
60 cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; |
80 cell.textLabel.text = [optionList objectAtIndex:[indexPath row]]; |
61 cell.textLabel.text = [controllerNames objectAtIndex:[indexPath row]]; |
81 } |
62 } |
82 |
63 |
83 return cell; |
64 return cell; |
84 } |
65 } |
85 |
66 |
113 |
94 |
114 #pragma mark - |
95 #pragma mark - |
115 #pragma mark Table view delegate |
96 #pragma mark Table view delegate |
116 -(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { |
97 -(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { |
117 int newRow = [indexPath row]; |
98 int newRow = [indexPath row]; |
118 int oldRow = (lastIndexPath != nil) ? [lastIndexPath row] : 0; |
99 int oldRow = (lastIndexPath != nil) ? [lastIndexPath row] : -1; |
|
100 UIViewController *nextController; |
119 |
101 |
120 if (newRow != oldRow) { |
102 if (newRow != oldRow) { |
121 [self.tableView deselectRowAtIndexPath:lastIndexPath animated:YES]; |
103 [self.tableView deselectRowAtIndexPath:lastIndexPath animated:YES]; |
122 [detailViewController.navigationController popToRootViewControllerAnimated:NO]; |
104 [detailViewController.navigationController popToRootViewControllerAnimated:NO]; |
123 |
105 |
124 UITableViewController *nextController = [self.controllers objectAtIndex:[indexPath row]]; |
106 switch (newRow) { |
|
107 case 0: |
|
108 if (nil == generalSettingsViewController) |
|
109 generalSettingsViewController = [[GeneralSettingsViewController alloc] initWithStyle:UITableViewStyleGrouped]; |
|
110 nextController = generalSettingsViewController; |
|
111 break; |
|
112 case 1: |
|
113 if (nil == teamSettingsViewController) |
|
114 teamSettingsViewController = [[TeamSettingsViewController alloc] initWithStyle:UITableViewStyleGrouped]; |
|
115 nextController = teamSettingsViewController; |
|
116 break; |
|
117 case 2: |
|
118 if (nil == weaponSettingsViewController) |
|
119 weaponSettingsViewController = [[WeaponSettingsViewController alloc] initWithStyle:UITableViewStyleGrouped]; |
|
120 nextController = weaponSettingsViewController; |
|
121 break; |
|
122 case 3: |
|
123 if (nil == schemeSettingsViewController) |
|
124 schemeSettingsViewController = [[SchemeSettingsViewController alloc] initWithStyle:UITableViewStyleGrouped]; |
|
125 nextController = schemeSettingsViewController; |
|
126 break; |
|
127 } |
|
128 |
|
129 nextController.navigationItem.hidesBackButton = YES; |
|
130 nextController.title = [controllerNames objectAtIndex:newRow]; |
125 [detailViewController.navigationController pushViewController:nextController animated:NO]; |
131 [detailViewController.navigationController pushViewController:nextController animated:NO]; |
126 self.lastIndexPath = indexPath; |
132 self.lastIndexPath = indexPath; |
127 [self.tableView selectRowAtIndexPath:indexPath animated:YES scrollPosition:UITableViewScrollPositionNone]; |
133 [self.tableView selectRowAtIndexPath:indexPath animated:YES scrollPosition:UITableViewScrollPositionNone]; |
128 } |
134 } |
129 } |
135 } |
135 // Releases the view if it doesn't have a superview. |
141 // Releases the view if it doesn't have a superview. |
136 [super didReceiveMemoryWarning]; |
142 [super didReceiveMemoryWarning]; |
137 // Relinquish ownership any cached data, images, etc that aren't in use. |
143 // Relinquish ownership any cached data, images, etc that aren't in use. |
138 } |
144 } |
139 |
145 |
140 - (void)dealloc { |
146 -(void) viewDidUnload { |
141 [optionList release]; |
147 self.detailViewController = nil; |
|
148 self.controllerNames = nil; |
|
149 self.lastIndexPath = nil; |
|
150 generalSettingsViewController = nil; |
|
151 teamSettingsViewController = nil; |
|
152 weaponSettingsViewController = nil; |
|
153 schemeSettingsViewController = nil; |
|
154 [super viewDidUnload]; |
|
155 } |
|
156 |
|
157 -(void) dealloc { |
|
158 [controllerNames release]; |
142 [detailViewController release]; |
159 [detailViewController release]; |
|
160 [lastIndexPath release]; |
|
161 [generalSettingsViewController release]; |
|
162 [teamSettingsViewController release]; |
|
163 [weaponSettingsViewController release]; |
|
164 [schemeSettingsViewController release]; |
143 [super dealloc]; |
165 [super dealloc]; |
144 } |
166 } |
145 |
167 |
146 -(IBAction) dismissSplitView { |
168 -(IBAction) dismissSplitView { |
147 [[NSNotificationCenter defaultCenter] postNotificationName:@"dismissModalView" object:nil]; |
169 [[NSNotificationCenter defaultCenter] postNotificationName:@"dismissModalView" object:nil]; |