iOS,UiSplitViewController 不与 AppDelegate 一起运行



我创建了一个带有拆分视图控制器窗口和应用程序代理的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->General->Main InterFace=Main iPad 中添加了

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

如果您想从代码中加载带有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];

此外,要点

相关内容

  • 没有找到相关文章

最新更新