Can't use UISplitViewController in a generic application?

I'm having trouble running UISplitViewController in a generic application, where I already encoded part of the iPhone. As a troubleshooting method, I decided to start with a new project and just try to perform one action that causes the problem, and it still exists.

If I create a universal application, and in the iPad controller I create a split view (either in XIB or in the code), then it looks black (if you do not set the background color). If I only do this in the iPad application, it displays just fine.

I would appreciate it if someone could check it out on their own and see if they get the same, or tell me where I am going wrong.

  • In Xcode, create a universal β€œwindow” application.
  • Log in to your iPad controller and paste the code below.

What I get is a black screen, not a split view. The same code works in iPad-only. What am I doing wrong, or what is wrong?

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { UISplitViewController *split = [[UISplitViewController alloc] initWithNibName:nil bundle:nil]; UIViewController *vc1 = [[UIViewController alloc] initWithNibName:nil bundle:nil]; vc1.view.backgroundColor = [UIColor redColor]; UIViewController *vc2 = [[UIViewController alloc] initWithNibName:nil bundle:nil]; vc2.view.backgroundColor = [UIColor blueColor]; split.viewControllers = [NSArray arrayWithObjects:vc1, vc2, nil]; [window addSubview:split.view]; [window makeKeyAndVisible]; [vc1 release]; [vc2 release]; [split release]; return YES; } 
+6
iphone uikit uisplitviewcontroller
source share
1 answer

First of all, you should not release your split view in the didFinishLaunchingWithOptions file. Add it to your interface (under UIWindow) and just release it to dealloc. Secondly, the subclass of UISplitViewController is as follows:

 @interface MySplitViewController : UISplitViewController { } @end @implementation MySplitViewController - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { return YES; } @end 

Thirdly, your doneFinishLaunchingWithOptions should look like this:

 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { split = [[MySplitViewController alloc] init]; UIViewController *vc1 = [[UIViewController alloc] init]; vc1.view.backgroundColor = [UIColor redColor]; UIViewController *vc2 = [[UIViewController alloc] init]; vc2.view.backgroundColor = [UIColor blueColor]; split.viewControllers = [NSArray arrayWithObjects:vc1, vc2, nil]; [window addSubview:split.view]; [window makeKeyAndVisible]; [vc1 release]; [vc2 release]; return YES; } 
+3
source share

All Articles