如何从UIViewController创建一个segue到UISplitViewController [英] How to create a segue from UIViewController to a UISplitViewController

查看:76
本文介绍了如何从UIViewController创建一个segue到UISplitViewController的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的iPad应用程序设置。我使用单视图应用程序创建了一个新项目 UIStoryboard

Here's my setup for an iPad app. I created a new project using the Single View Application with UIStoryboard.

XCode创建了主 UIViewController 作为入口点。在视图中,我放置了一个带有按钮的工具栏。然后我在storboard上插入一个 UISplitViewController

XCode created the main UIViewController as the entry point. In the view I placed a toolbar with a button. I then insterted a UISplitViewController to the storboard.

我想要的是从工具栏中得到一个按钮使用主/明细表加载拆分视图。

What I want is from the toolbar to have a button that will load the split view with master/detail tables.

我试图点击按钮并拖动到splitviewcontroller,它创建了一个segue,但我创建的每个组合都未能运行并崩溃。

I tried to click on the button and drag to the splitviewcontroller, which created a segue, but every combination I created failed to run and crashed.

我的工具栏中还有许多其他按钮可以加载其他视图。

My toolbar will have many other buttons which will load other views.

问题是,如何使用故事板链接加载拆分视图的配置?所有谷歌搜索结果都没有显示这样的设置示例。

The question is, how do I use storyboard to link the configuration of loading the split view? All google results showed me no examples of such a setup.

提前致谢

推荐答案

你做不到。拆分视图控制器必须是窗口的根视图控制器。

You can't do that. A split view controller has to be the root view controller of the window.

从View Controller Catalog for iOS:拆分视图控制器必须始终是您创建的任何接口的根。换句话说,您必须始终安装从UISplitViewController对象查看作为应用程序窗口的根视图。

From the "View Controller Catalog for iOS" : "A split view controller must always be the root of any interface you create. In other words, you must always install the view from a UISplitViewController object as the root view of your application’s window."

编辑后:我刚刚尝试了我在评论中提到的代码方法,并且它有效。因此,在故事板中,您可以按照自己的方式设置控制器,只是不要在第一个控制器和拆分视图控制器之间建立任何连接。然后在代码中使用以下代码切换到它:

After I just tried the code method that I mentioned in my comment, and it worked. So, in your storyboard, you can set up the controllers the way you want, just don't make any connection between your first controller and the split view controller. Then in code switch to it with this code:

-(IBAction)switchToSplit:(id)sender {
    UISplitViewController *split = [self.storyboard instantiateViewControllerWithIdentifier:@"Split"];
    self.view.window.rootViewController = split;
}

这篇关于如何从UIViewController创建一个segue到UISplitViewController的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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