在Objective-C中从UIViewController显示一个SplitViewController [英] display a SplitViewController from UIViewController in Objective-C

查看:128
本文介绍了在Objective-C中从UIViewController显示一个SplitViewController的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用一个按钮开发一个ViewController(登录应用程序),当我按下这个按钮时,我想像这样出现我的UISplitView:

I am developing a ViewController (login app) with a single button, when I press this button I want to appear my UISplitView like this:

- (IBAction)loadSplitViewController:(id)sender {

    [self showSplitViewController];
}

并且为创建我的splitViewController而开发的代码是:

and the code developed for the creation of my splitViewController is this:

-(void)showSplitViewController{

    UIStoryboard *mainStoryboard                    = [UIStoryboard storyboardWithName:@"MainStoryboard_iPad" bundle: nil];

    LeftViewController      *leftViewController     = [mainStoryboard instantiateViewControllerWithIdentifier:@"LeftViewController"];
    RightViewController     *rightViewController    = [mainStoryboard instantiateViewControllerWithIdentifier:@"RightViewController"];

    UINavigationController  *leftNavController      = [[UINavigationController alloc] initWithRootViewController:leftViewController];
    UINavigationController  *rightNavController     = [[UINavigationController alloc] initWithRootViewController:rightViewController];

    UISplitViewController   *splitViewController    = [[UISplitViewController alloc] init];
    splitViewController.viewControllers             = [NSArray arrayWithObjects:leftNavController, rightNavController, nil];

    leftViewController.delegate     = rightViewController;
    splitViewController.delegate    = rightViewController;

    [self presentViewController:splitViewController animated:YES completion:^{}];
}

事情是......如果我用于显示我的splitViewController这一行:

the thing is... if I use for display my splitViewController this line:

[self presentViewController:splitViewController animated:YES completion:^{}];

给我一​​个错误

我也是试过

[self.view addSubview:splitViewController.view];

但这样我的splitViewController永远不会旋转,代理也不能正常工作......而我不希望我的splitViewController成为我的viewController的子视图,我希望它看起来更像是一个独立的modalView

but this way my splitViewController never rotates, and delegates doesn't work as well... and I don't want my splitViewController to be a subview of my viewController, I want it to appear more like an independient modalView

任何帮助我都会感激

提前谢谢

推荐答案

拆分视图控制器确实应该是根视图控制器窗口(实际上Apple说它必须是,但似乎有一些例子,这不是真的)。您只需将窗口的根视图控制器切换为拆分视图控制器,而不是显示它。

Split view controllers really should be the root view controller of the window (in fact Apple says it has to be, though there seem to be some examples where this isn't true). Instead of presenting it, you could just switch the window's root view controller to be the split view controller.

self.view.window.rootViewController = splitViewController;

这篇关于在Objective-C中从UIViewController显示一个SplitViewController的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆