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
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;
}
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?
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