|
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 #import "CommodityFunctions.h" |
|
13 |
|
14 @implementation SplitViewRootController |
|
15 |
|
16 |
|
17 -(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { |
|
18 return rotationManager(interfaceOrientation); |
|
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 if (detailViewController.view.superview == nil) |
|
26 detailViewController = nil; |
|
27 MSG_MEMCLEAN(); |
|
28 } |
|
29 |
|
30 // load the view programmatically; we need a splitViewController that handles a MasterViewController |
|
31 // (which is just a UITableViewController) and a DetailViewController where we present options |
|
32 -(void) viewDidLoad { |
|
33 detailViewController = [[DetailViewController alloc] initWithStyle:UITableViewStyleGrouped]; |
|
34 UINavigationController *detailedNavController = [[UINavigationController alloc] initWithRootViewController:detailViewController]; |
|
35 [detailViewController release]; |
|
36 |
|
37 CGRect rect = [[UIScreen mainScreen] bounds]; |
|
38 if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) |
|
39 self.view.frame = CGRectMake(0, 0, rect.size.height, rect.size.width); |
|
40 |
|
41 if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { |
|
42 UISplitViewController *splitViewRootController = [[UISplitViewController alloc] init]; |
|
43 //splitViewRootController.view.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth; |
|
44 splitViewRootController.view.frame = CGRectMake(0, 0, rect.size.height, rect.size.width); |
|
45 |
|
46 MasterViewController *masterViewController = [[MasterViewController alloc] initWithStyle:UITableViewStylePlain]; |
|
47 UINavigationController *mainNavController = [[UINavigationController alloc] initWithRootViewController:masterViewController]; |
|
48 [masterViewController release]; |
|
49 |
|
50 splitViewRootController.delegate = detailViewController; |
|
51 masterViewController.detailViewController = detailViewController; |
|
52 splitViewRootController.viewControllers = [NSArray arrayWithObjects: mainNavController, detailedNavController, nil]; |
|
53 [mainNavController release]; |
|
54 [detailedNavController release]; |
|
55 |
|
56 // add view to main controller |
|
57 [self.view addSubview:splitViewRootController.view]; |
|
58 } else { |
|
59 [self.view addSubview:detailedNavController.view]; |
|
60 } |
|
61 |
|
62 [super viewDidLoad]; |
|
63 } |
|
64 |
|
65 -(void) viewDidUnload { |
|
66 detailViewController = nil; |
|
67 [super viewDidUnload]; |
|
68 MSG_DIDUNLOAD(); |
|
69 } |
|
70 |
|
71 -(void) dealloc { |
|
72 [detailViewController release]; |
|
73 [super dealloc]; |
|
74 } |
|
75 -(void) willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration{ |
|
76 [detailViewController willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration]; |
|
77 } |
|
78 |
|
79 #pragma mark - |
|
80 #pragma mark additional methods as we're using a UINavigationController programmatically |
|
81 // see http://davidebenini.it/2009/01/03/viewwillappear-not-being-called-inside-a-uinavigationcontroller/ |
|
82 -(void) viewWillAppear:(BOOL)animated { |
|
83 [super viewWillAppear:animated]; |
|
84 [detailViewController.navigationController viewWillAppear:animated]; |
|
85 } |
|
86 |
|
87 -(void) viewWillDisappear:(BOOL)animated { |
|
88 [super viewWillDisappear:animated]; |
|
89 [detailViewController.navigationController viewWillDisappear:animated]; |
|
90 } |
|
91 |
|
92 -(void) viewDidAppear:(BOOL)animated { |
|
93 [super viewDidLoad]; |
|
94 [detailViewController.navigationController viewDidAppear:animated]; |
|
95 } |
|
96 |
|
97 -(void) viewDidDisappear:(BOOL)animated { |
|
98 [super viewDidUnload]; |
|
99 [detailViewController.navigationController viewDidDisappear:animated]; |
|
100 } |
|
101 |
|
102 |
|
103 @end |