2

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

Bartłomiej Semańczyk
  • 59,234
  • 49
  • 233
  • 358
IIS7 Rewrite
  • 779
  • 3
  • 16
  • 31

3 Answers3

7

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;
}
rdelmar
  • 103,982
  • 12
  • 207
  • 218
  • 2
    Wow, that's ridiculous! You (meaning Apple) mean that every app that uses a UISplitViewController actually starts with it? I've seen many apps that use a split view but did not start with it. How did they do it? – IIS7 Rewrite Dec 11 '12 at 03:09
  • @IIS7Rewrite, You can present a modal view controller from the viewDidAppear method of one of the split view's controllers, so it will appear right away when the app loads. You might also be able to reset the window's root view controller in code from another view controller that you start the app with. I haven't tried that. – rdelmar Dec 11 '12 at 03:11
  • I'd be more interested in the second solution if it works, since the first one sounds a little off, at least when it comes to design patterns. I'd be interested to know if someone has done such a thing. I can't imagine this to be a rare case. – IIS7 Rewrite Dec 11 '12 at 03:23
  • by the way, I just tried it too with an example I made and it works perfectly. thanks again. – IIS7 Rewrite Dec 11 '12 at 04:06
  • Apple no longer require UISplitViewController to be the root view controller. See the docs now and Apple's own Podcast app which puts UISVC instead of a UITabBarController. – Steve Moser Mar 23 '16 at 18:43
0

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?

Community
  • 1
  • 1
Jan Bühler
  • 421
  • 3
  • 18
0

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.

Steve Moser
  • 7,647
  • 5
  • 55
  • 94