19 */ |
19 */ |
20 |
20 |
21 |
21 |
22 #import "SettingsContainerViewController.h" |
22 #import "SettingsContainerViewController.h" |
23 #import "SettingsBaseViewController.h" |
23 #import "SettingsBaseViewController.h" |
|
24 #import "MGSplitViewController.h" |
24 |
25 |
25 |
26 |
26 @implementation SettingsContainerViewController |
27 @implementation SettingsContainerViewController |
27 @synthesize baseController, activeController, splitViewRootController; |
28 @synthesize baseController, splitViewRootController; |
28 |
29 |
29 -(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { |
30 -(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { |
30 return rotationManager(interfaceOrientation); |
31 return rotationManager(interfaceOrientation); |
31 } |
32 } |
32 |
33 |
33 |
34 |
34 -(void) viewDidLoad { |
35 -(void) viewDidLoad { |
35 CGRect rect = [[UIScreen mainScreen] bounds]; |
36 CGRect screenRect = [[UIScreen mainScreen] safeBounds]; |
36 self.view.frame = CGRectMake(0, 0, rect.size.height, rect.size.width); |
37 self.view.frame = screenRect; |
37 |
38 |
38 if (IS_IPAD()) { |
39 if (IS_IPAD()) { |
39 // the contents on the right of the splitview, setting targetController to nil to avoid creating the table |
40 // the contents on the right of the splitview, setting targetController to nil to avoid creating the table |
40 SettingsBaseViewController *rightController = [[SettingsBaseViewController alloc] init]; |
41 SettingsBaseViewController *rightController = [[SettingsBaseViewController alloc] init]; |
41 rightController.targetController = nil; |
42 rightController.targetController = nil; |
46 SettingsBaseViewController *leftController = [[SettingsBaseViewController alloc] init]; |
47 SettingsBaseViewController *leftController = [[SettingsBaseViewController alloc] init]; |
47 leftController.targetController = rightNavController.topViewController; |
48 leftController.targetController = rightNavController.topViewController; |
48 UINavigationController *leftNavController = [[UINavigationController alloc] initWithRootViewController:leftController]; |
49 UINavigationController *leftNavController = [[UINavigationController alloc] initWithRootViewController:leftController]; |
49 [leftController release]; |
50 [leftController release]; |
50 |
51 |
51 self.activeController = rightNavController; |
52 self.splitViewRootController = [[MGSplitViewController alloc] init]; |
52 self.splitViewRootController = [[UISplitViewController alloc] init]; |
|
53 self.splitViewRootController.delegate = nil; |
53 self.splitViewRootController.delegate = nil; |
54 self.splitViewRootController.view.frame = CGRectMake(0, 0, rect.size.height, rect.size.width); |
54 self.splitViewRootController.view.frame = screenRect; |
55 self.splitViewRootController.viewControllers = [NSArray arrayWithObjects: leftNavController, rightNavController, nil]; |
55 self.splitViewRootController.viewControllers = [NSArray arrayWithObjects: leftNavController, rightNavController, nil]; |
|
56 self.splitViewRootController.showsMasterInPortrait = YES; |
56 [leftNavController release]; |
57 [leftNavController release]; |
57 [rightNavController release]; |
58 [rightNavController release]; |
58 |
59 |
59 // add view to main controller |
60 // add view to main controller |
60 [self.view addSubview:self.splitViewRootController.view]; |
61 [self.view addSubview:self.splitViewRootController.view]; |
76 #pragma mark - |
77 #pragma mark - |
77 #pragma mark Memory management |
78 #pragma mark Memory management |
78 -(void) didReceiveMemoryWarning { |
79 -(void) didReceiveMemoryWarning { |
79 if (self.baseController.view.superview == nil) |
80 if (self.baseController.view.superview == nil) |
80 self.baseController = nil; |
81 self.baseController = nil; |
81 if (self.activeController.view.superview == nil) |
|
82 self.activeController = nil; |
|
83 if (self.splitViewRootController.view.superview == nil) |
82 if (self.splitViewRootController.view.superview == nil) |
84 self.splitViewRootController = nil; |
83 self.splitViewRootController = nil; |
85 MSG_MEMCLEAN(); |
84 MSG_MEMCLEAN(); |
86 [super didReceiveMemoryWarning]; |
85 [super didReceiveMemoryWarning]; |
87 } |
86 } |
88 |
87 |
89 -(void) viewDidUnload { |
88 -(void) viewDidUnload { |
90 self.baseController = nil; |
89 self.baseController = nil; |
91 self.activeController = nil; |
|
92 self.splitViewRootController = nil; |
90 self.splitViewRootController = nil; |
93 MSG_DIDUNLOAD(); |
91 MSG_DIDUNLOAD(); |
94 [super viewDidUnload]; |
92 [super viewDidUnload]; |
95 } |
93 } |
96 |
94 |
97 -(void) dealloc { |
95 -(void) dealloc { |
98 releaseAndNil(baseController); |
96 releaseAndNil(baseController); |
99 releaseAndNil(activeController); |
|
100 releaseAndNil(splitViewRootController); |
97 releaseAndNil(splitViewRootController); |
101 [super dealloc]; |
98 [super dealloc]; |
102 } |
99 } |
103 |
100 |
104 |
101 |
105 #pragma mark - |
102 #pragma mark - |
106 #pragma mark view event management propagation |
103 #pragma mark view event management propagation |
107 // every time we add a uiviewcontroller programmatically we need to take care of propgating such messages |
104 // every time we add a uiviewcontroller programmatically we need to take care of propgating such messages |
108 // see http://davidebenini.it/2009/01/03/viewwillappear-not-being-called-inside-a-uinavigationcontroller/ |
105 // see http://davidebenini.it/2009/01/03/viewwillappear-not-being-called-inside-a-uinavigationcontroller/ |
109 -(void) viewWillAppear:(BOOL)animated { |
106 -(void) viewWillAppear:(BOOL)animated { |
110 [self.activeController viewWillAppear:animated]; |
107 [self.splitViewRootController.detailViewController viewWillAppear:animated]; |
111 [self.baseController viewWillAppear:animated]; |
108 [self.baseController viewWillAppear:animated]; |
112 [super viewWillAppear:animated]; |
109 [super viewWillAppear:animated]; |
113 } |
110 } |
114 |
111 |
115 -(void) viewWillDisappear:(BOOL)animated { |
112 -(void) viewWillDisappear:(BOOL)animated { |
116 [self.activeController viewWillDisappear:animated]; |
113 [self.splitViewRootController.detailViewController viewWillDisappear:animated]; |
117 [self.baseController viewWillDisappear:animated]; |
114 [self.baseController viewWillDisappear:animated]; |
118 [super viewWillDisappear:animated]; |
115 [super viewWillDisappear:animated]; |
119 } |
116 } |
120 |
117 |
121 -(void) viewDidAppear:(BOOL)animated { |
118 -(void) viewDidAppear:(BOOL)animated { |
122 [self.activeController viewDidAppear:animated]; |
119 [self.splitViewRootController.detailViewController viewDidAppear:animated]; |
123 [self.baseController viewDidAppear:animated]; |
120 [self.baseController viewDidAppear:animated]; |
124 [super viewDidLoad]; |
121 [super viewDidLoad]; |
125 } |
122 } |
126 |
123 |
127 -(void) viewDidDisappear:(BOOL)animated { |
124 -(void) viewDidDisappear:(BOOL)animated { |
128 [self.activeController viewDidDisappear:animated]; |
125 [self.splitViewRootController.detailViewController viewDidDisappear:animated]; |
129 [self.baseController viewDidDisappear:animated]; |
126 [self.baseController viewDidDisappear:animated]; |
130 [super viewDidUnload]; |
127 [super viewDidUnload]; |
131 } |
128 } |
132 |
129 |
|
130 -(void) willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration { |
|
131 if (IS_IPAD() == NO) |
|
132 return; |
|
133 |
|
134 CGRect screenRect = [[UIScreen mainScreen] safeBounds]; |
|
135 self.splitViewRootController.masterViewController.view.frame = CGRectMake(0, 0, 320, screenRect.size.height); |
|
136 } |
133 |
137 |
134 @end |
138 @end |