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 |
13 |
14 @implementation MasterViewController |
14 @implementation MasterViewController |
15 @synthesize detailViewController, optionList, controllers; |
15 @synthesize detailViewController, optionList, controllers, lastIndexPath; |
16 |
16 |
17 #pragma mark - |
17 #pragma mark - |
18 #pragma mark View lifecycle |
18 #pragma mark View lifecycle |
19 |
|
20 |
|
21 - (void)viewDidLoad { |
19 - (void)viewDidLoad { |
22 [super viewDidLoad]; |
20 [super viewDidLoad]; |
|
21 |
|
22 // the list of selectable controllers |
23 optionList = [[NSArray alloc] initWithObjects:NSLocalizedString(@"General",@""), |
23 optionList = [[NSArray alloc] initWithObjects:NSLocalizedString(@"General",@""), |
24 NSLocalizedString(@"Teams",@""), |
24 NSLocalizedString(@"Teams",@""), |
25 NSLocalizedString(@"Weapons",@""), |
25 NSLocalizedString(@"Weapons",@""), |
26 NSLocalizedString(@"Schemes",@""), |
26 NSLocalizedString(@"Schemes",@""), |
27 nil]; |
27 nil]; |
|
28 // the "Done" button on top left |
28 self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:0 |
29 self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:0 |
29 target:self |
30 target:self |
30 action:@selector(dismissSplitView)]; |
31 action:@selector(dismissSplitView)]; |
31 |
32 // list of allocated viewcontrollers (same in DetailViewController) |
32 NSMutableArray *array= [[NSMutableArray alloc] init]; |
33 NSMutableArray *array= [[NSMutableArray alloc] init]; |
33 |
34 |
34 GeneralSettingsViewController *generalSettingsViewController = [[GeneralSettingsViewController alloc] |
35 GeneralSettingsViewController *generalSettingsViewController = [[GeneralSettingsViewController alloc] |
35 initWithStyle:UITableViewStyleGrouped]; |
36 initWithStyle:UITableViewStyleGrouped]; |
36 generalSettingsViewController.title = NSLocalizedString(@"General",@""); |
37 generalSettingsViewController.title = NSLocalizedString(@"General",@""); |
45 [array addObject:teamSettingsViewController]; |
46 [array addObject:teamSettingsViewController]; |
46 [teamSettingsViewController release]; |
47 [teamSettingsViewController release]; |
47 |
48 |
48 self.controllers = array; |
49 self.controllers = array; |
49 [array release]; |
50 [array release]; |
50 // Uncomment the following line to preserve selection between presentations. |
|
51 //self.clearsSelectionOnViewWillAppear = NO; |
|
52 // Uncomment the following line to display an Edit button in the navigation bar for this view controller. |
|
53 //self.navigationItem.rightBarButtonItem = self.editButtonItem; |
|
54 } |
51 } |
55 |
52 |
56 -(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { |
53 -(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { |
57 return (interfaceOrientation == UIInterfaceOrientationLandscapeRight); |
54 return (interfaceOrientation == UIInterfaceOrientationLandscapeRight); |
58 } |
55 } |
113 */ |
110 */ |
114 |
111 |
115 #pragma mark - |
112 #pragma mark - |
116 #pragma mark Table view delegate |
113 #pragma mark Table view delegate |
117 -(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { |
114 -(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { |
|
115 int newRow = [indexPath row]; |
|
116 int oldRow = (lastIndexPath != nil) ? [lastIndexPath row] : 0; |
118 |
117 |
119 [detailViewController.navigationController popToRootViewControllerAnimated:NO]; |
118 if (newRow != oldRow) { |
120 |
119 [detailViewController.navigationController popToRootViewControllerAnimated:NO]; |
121 NSInteger row = [indexPath row]; |
120 |
122 UITableViewController *nextController = [self.controllers objectAtIndex:row]; |
121 UITableViewController *nextController = [self.controllers objectAtIndex:[indexPath row]]; |
123 [detailViewController.navigationController pushViewController:nextController animated:YES]; |
122 [detailViewController.navigationController pushViewController:nextController animated:YES]; |
|
123 self.lastIndexPath = indexPath; |
|
124 [self.tableView selectRowAtIndexPath:indexPath animated:YES scrollPosition:UITableViewScrollPositionNone]; |
|
125 } |
|
126 [self.tableView deselectRowAtIndexPath:indexPath animated:YES]; |
124 } |
127 } |
125 |
128 |
126 |
129 |
127 #pragma mark - |
130 #pragma mark - |
128 #pragma mark Memory management |
131 #pragma mark Memory management |
129 -(void) didReceiveMemoryWarning { |
132 -(void) didReceiveMemoryWarning { |
130 // Releases the view if it doesn't have a superview. |
133 // Releases the view if it doesn't have a superview. |
131 [super didReceiveMemoryWarning]; |
134 [super didReceiveMemoryWarning]; |
132 |
|
133 // Relinquish ownership any cached data, images, etc that aren't in use. |
135 // Relinquish ownership any cached data, images, etc that aren't in use. |
134 } |
136 } |
135 |
137 |
136 - (void)dealloc { |
138 - (void)dealloc { |
137 [optionList release]; |
139 [optionList release]; |