cocoaTouch/iPad/SplitViewRootController.m
changeset 3250 d5cd1a617123
parent 3113 2829ea0dd47c
child 3270 9bd8fb1707b9
--- a/cocoaTouch/iPad/SplitViewRootController.m	Fri Apr 02 10:50:10 2010 +0000
+++ b/cocoaTouch/iPad/SplitViewRootController.m	Fri Apr 02 12:38:36 2010 +0000
@@ -29,18 +29,25 @@
 -(void) viewDidLoad {
     // init every possible controller
     splitViewController = [[UISplitViewController alloc] init];
-    detailViewController = [[DetailViewController alloc] initWithNibName:@"DetailViewController" bundle:nil];
     masterViewController = [[MasterViewController alloc] initWithStyle:UITableViewStylePlain];
-    UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:masterViewController];
-
+    detailViewController = [[DetailViewController alloc] initWithStyle:UITableViewStyleGrouped];
+    
+    UINavigationController *mainNavController = [[UINavigationController alloc] initWithRootViewController:masterViewController];
+    UINavigationController *detailedNavController = [[UINavigationController alloc] initWithRootViewController:detailViewController];
+    
     // set attributes
     masterViewController.detailViewController = detailViewController;
-    splitViewController.viewControllers = [NSArray arrayWithObjects:navigationController, detailViewController, nil];
-	splitViewController.delegate = detailViewController;
+    splitViewController.viewControllers = [NSArray arrayWithObjects: mainNavController, detailedNavController, nil];
+    [mainNavController release];
+    [detailedNavController release];
+	
+    splitViewController.delegate = detailViewController;
     
     // add view to main controller
     [self.view addSubview:splitViewController.view];
-     
+    [detailViewController release];
+    [masterViewController release];
+
     [super viewDidLoad];
 }
 
@@ -51,5 +58,28 @@
     [super dealloc];
 }
 
+#pragma mark -
+#pragma mark additional methods as we're using a UINavigationController programmatically
+// see http://davidebenini.it/2009/01/03/viewwillappear-not-being-called-inside-a-uinavigationcontroller/
+-(void) viewWillAppear:(BOOL)animated {
+    [super viewWillAppear:animated];
+    [detailViewController.navigationController viewWillAppear:animated];
+}
+
+-(void) viewWillDisappear:(BOOL)animated {
+    [super viewWillDisappear:animated];
+    [detailViewController.navigationController viewWillDisappear:animated];
+}
+
+-(void) viewDidAppear:(BOOL)animated {
+    [super viewDidLoad];
+    [detailViewController.navigationController viewDidAppear:animated];
+}
+
+-(void) viewDidDisappear:(BOOL)animated {
+    [super viewDidUnload];
+    [detailViewController.navigationController viewDidDisappear:animated];
+}
+
 
 @end