1

I am trying to get a split controller's view by calling it in AppDelegate, but it's not showing up. Here is the code written in didfinishlaunchwithoptions :

self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.

SplitViewController *splitViewController = [[SplitViewController alloc] initWithNibName:@"SplitViewController" bundle:nil];
self.navigationController = [[UINavigationController alloc] initWithRootViewController:splitViewController];
self.window.rootViewController = self.navigationController;
[self.window makeKeyAndVisible];
return YES;

And i have SplitViewController.xib with view red colored. But iPad simulator turn up with a black screen.

Please see what can be the issue.

Thanks

turtle
  • 928
  • 1
  • 11
  • 23
  • Are you getting any errors or output in the console? Perhaps the xib file's "view" property is not set or something like that. – borrrden Mar 18 '12 at 03:52
  • no I am taking care of that, but a different one: Split View Controllers cannot be pushed to a Navigation Controller . – turtle Mar 18 '12 at 03:53
  • see http://stackoverflow.com/questions/6855454/how-can-we-push-uisplitviewcontroller-to-a-uinavigationcontroller – borrrden Mar 18 '12 at 03:56
  • but i tried by removing the NC object and setting the window's rootViewController = splitViewController; But this also seems not working. I also tried by adding the view of splitViewController on window, but this again results in a black window on simulator. – turtle Mar 18 '12 at 03:59
  • And once again, I will ask if there were any console messages... – borrrden Mar 18 '12 at 04:01
  • I have added the GDB message below..please see. – turtle Mar 18 '12 at 04:03

3 Answers3

3

Split View Controllers cannot be pushed to a Navigation Controller

This is the key here. Try adding your split view controller directly to your window.

self.window.rootViewController = self.splitViewController;
Vignesh
  • 10,205
  • 2
  • 35
  • 73
  • My SplitViewController class is a subclass of UISplitViewController, i guess I am not doing any mistakes here? – turtle Mar 18 '12 at 04:02
  • 2012-03-18 09:30:56.475 MapApp[707:f803] Splitview controller is expected to have a master view controller before its used! 2012-03-18 09:30:56.477 MapApp[707:f803] Splitview controller is expected to have a detail children before its used! 2012-03-18 09:30:56.478 MapApp[707:f803] Split view controller should have its children set before layout! – turtle Mar 18 '12 at 04:03
  • if your splitview is made correctly it should work. but you can try "[self.window addSubview:self.splitViewController.view];". – Vignesh Mar 18 '12 at 04:09
1

You are not setting up the view correctly in your nib. Split view controllers need to have two views set, a master view and a detail view. Your detail view is not set so the viewcontroller is never created.

The docs on UISplitViewController state that you need to have the viewControllers property set to exactly two views. I imagine you are only setting one (the red view).

edit: You didn't set the master view either....so it is close to what I said before in the comments (the view is not set properly)

borrrden
  • 33,256
  • 8
  • 74
  • 109
0
AppDemoMasterViewController *masterViewController = [[[AppDemoMasterViewController alloc] initWithNibName:@"AppDemoMasterViewController_iPad" bundle:nil] autorelease];

UINavigationController *masterNavigationController = [[[UINavigationController alloc] initWithRootViewController:masterViewController] autorelease];    

AppDemoDetailViewController *masterViewController = [[[AppDemoDetailViewController alloc] initWithNibName:@"AppDemoDetailViewController_iPad" bundle:nil] autorelease];

UINavigationController *detailNavigationController = [[[UINavigationController alloc] initWithRootViewController:detailViewController] autorelease];

self.splitViewController.viewControllers = [NSArray arrayWithObjects:masterNavigationController, detailNavigationController, nil];

self.window.rootViewController = self.splitViewController;
elp
  • 8,021
  • 7
  • 61
  • 120
Bulla
  • 924
  • 1
  • 7
  • 15