How to create a segue from UIViewController to a UISplitViewController

六月ゝ 毕业季﹏ 提交于 2019-12-02 02:34:48

问题


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

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.

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.

Thanks in advance


回答1:


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

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 Edit: 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;
}



回答2:


While the split view controller has to be the root view controller of its window, an app can have multiple windows. Sadly, this concept is hardly known by developers and works only programatically and not via Interface builder (to my knowledge). I believe the following answer can help with your issue:

How to use a UISplitViewController as a Modal View Controller?




回答3:


You might want to use a UITabBarViewController. Although Apple doesn't require UISplitViewController to be the root view controller they encourage it in most cases unless you're using it inside of a UITabBarViewController like Apple's Podcast app.



来源:https://stackoverflow.com/questions/13812942/how-to-create-a-segue-from-uiviewcontroller-to-a-uisplitviewcontroller

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!