iOS,UiSplitViewController不能与AppDelegate一起运行

时间:2014-10-24 10:57:04

标签: ipad uistoryboard appdelegate uiwindow uisplitview

我使用Split View Controller Windows和App Delegate创建一个Main-iPad.Storyboard

这是我的应用程序Delegate.h

   IBOutlet UISplitViewController * rootcontroler;
   UIWindow *window;

这是我的应用程序Delegate.m

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    


    UIStoryboard * storyboard = [UIStoryboard storyboardWithName:@"Main-iPad" bundle:nil];
    UIViewController *initviewcontroller = [storyboard instantiateInitialViewController];
    [self.window setRootViewController:initviewcontroller];



}

我添加了Target->一般 - >主要InterFace =主要iPad

但是当我运行应用程序时,我收到了黑屏

1 个答案:

答案 0 :(得分:0)

如果您要从代码中使用UISplitViewController初始vc加载故事板,请从目标 Info.plist 中删除相应的密钥,并将此代码添加到AppDelegate.m

// loading initial vc the way many folks around do
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:[NSBundle mainBundle]];
UIViewController *vc =[storyboard instantiateInitialViewController];
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.rootViewController = vc;

// set up split vc
self.splitViewController = (UISplitViewController *)self.window.rootViewController;
UINavigationController *navigationController = [self.splitViewController.viewControllers lastObject];
navigationController.topViewController.navigationItem.leftBarButtonItem = self.splitViewController.displayModeButtonItem;
navigationController.topViewController.navigationItem.leftItemsSupplementBackButton = YES;
self.splitViewController.delegate = self;
self.splitViewController.preferredDisplayMode = UISplitViewControllerDisplayModeAllVisible;
self.splitViewController.preferredPrimaryColumnWidthFraction = 0.5;
// do any other split vc customization if needed

// this is an important part: call this _after_ split vc set up, otherwise you'd get wrong collapsed vc presented by split vc
[self.window makeKeyAndVisible];

另外,the gist