1 // |
|
2 // SplitViewRootController.m |
|
3 // HedgewarsMobile |
|
4 // |
|
5 // Created by Vittorio on 27/03/10. |
|
6 // Copyright 2010 __MyCompanyName__. All rights reserved. |
|
7 // |
|
8 |
|
9 #import "SplitViewRootController.h" |
|
10 #import "MasterViewController.h" |
|
11 #import "DetailViewController.h" |
|
12 |
|
13 @implementation SplitViewRootController |
|
14 @synthesize splitViewController, masterViewController, detailViewController; |
|
15 |
|
16 |
|
17 -(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { |
|
18 return (interfaceOrientation == UIInterfaceOrientationLandscapeRight); |
|
19 } |
|
20 |
|
21 -(void) didReceiveMemoryWarning { |
|
22 // Releases the view if it doesn't have a superview. |
|
23 [super didReceiveMemoryWarning]; |
|
24 // Release any cached data, images, etc that aren't in use. |
|
25 } |
|
26 |
|
27 // load the view programmatically; we need a splitViewController that handles a MasterViewController |
|
28 // (which is just a UITableViewController) and a DetailViewController where we present options |
|
29 -(void) viewDidLoad { |
|
30 // init every possible controller |
|
31 splitViewController = [[UISplitViewController alloc] init]; |
|
32 CGRect screensize = [[UIScreen mainScreen] bounds]; |
|
33 splitViewController.view.frame = CGRectMake(0, 0, screensize.size.height, screensize.size.width); |
|
34 masterViewController = [[MasterViewController alloc] initWithStyle:UITableViewStylePlain]; |
|
35 detailViewController = [[DetailViewController alloc] initWithStyle:UITableViewStyleGrouped]; |
|
36 |
|
37 UINavigationController *mainNavController = [[UINavigationController alloc] initWithRootViewController:masterViewController]; |
|
38 UINavigationController *detailedNavController = [[UINavigationController alloc] initWithRootViewController:detailViewController]; |
|
39 |
|
40 // set attributes |
|
41 masterViewController.detailViewController = detailViewController; |
|
42 splitViewController.viewControllers = [NSArray arrayWithObjects: mainNavController, detailedNavController, nil]; |
|
43 [mainNavController release]; |
|
44 [detailedNavController release]; |
|
45 |
|
46 splitViewController.delegate = detailViewController; |
|
47 |
|
48 // add view to main controller |
|
49 [self.view addSubview:splitViewController.view]; |
|
50 [detailViewController release]; |
|
51 [masterViewController release]; |
|
52 |
|
53 [super viewDidLoad]; |
|
54 } |
|
55 |
|
56 -(void) dealloc { |
|
57 [detailViewController release]; |
|
58 [masterViewController release]; |
|
59 [splitViewController release]; |
|
60 [super dealloc]; |
|
61 } |
|
62 |
|
63 #pragma mark - |
|
64 #pragma mark additional methods as we're using a UINavigationController programmatically |
|
65 // see http://davidebenini.it/2009/01/03/viewwillappear-not-being-called-inside-a-uinavigationcontroller/ |
|
66 -(void) viewWillAppear:(BOOL)animated { |
|
67 [super viewWillAppear:animated]; |
|
68 [detailViewController.navigationController viewWillAppear:animated]; |
|
69 } |
|
70 |
|
71 -(void) viewWillDisappear:(BOOL)animated { |
|
72 [super viewWillDisappear:animated]; |
|
73 [detailViewController.navigationController viewWillDisappear:animated]; |
|
74 } |
|
75 |
|
76 -(void) viewDidAppear:(BOOL)animated { |
|
77 [super viewDidLoad]; |
|
78 [detailViewController.navigationController viewDidAppear:animated]; |
|
79 } |
|
80 |
|
81 -(void) viewDidDisappear:(BOOL)animated { |
|
82 [super viewDidUnload]; |
|
83 [detailViewController.navigationController viewDidDisappear:animated]; |
|
84 } |
|
85 |
|
86 |
|
87 @end |
|