Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Split view controller must be root view controller

Whenever I try to present a UISplitViewController modally the application crashes. Thus it must allways be the root view controller. Can anyone confirm that?

like image 420
user309305 Avatar asked Apr 05 '10 17:04

user309305


People also ask

How do I know if my view controller is root view controller?

The root view controller is simply the view controller that sits at the bottom of the navigation stack. You can access the navigation controller's array of view controllers through its viewControllers property. To access the root view controller, we ask for the first item of the array of view controllers.

What is a root controller?

The root view controller provides the content view of the window. Assigning a view controller to this property (either programmatically or using Interface Builder) installs the view controller's view as the content view of the window.

What is UISplitViewController?

A split view controller is a container view controller that manages child view controllers in a hierarchical interface. In this type of interface, changes in one view controller drive changes in the content of another.

What is a navigation controller Swift?

A navigation controller is a container view controller that manages one or more child view controllers in a navigation interface. In this type of interface, only one child view controller is visible at a time.


4 Answers

From the Apple iPad Programming Guide:

The split view controller’s view should always be installed as the root view of your application window. You should never present a split view inside of a navigation or tab bar interface.

So yes, you cannot present a split view outside of your main application window (that includes modally).

EDIT

The link to the docs above no longer discusses this topic. Relevant discussion can now be found at Apple's View Controller Catalog for iOS, which states the following:

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. [...] Split view controllers cannot be presented modally.

like image 171
indragie Avatar answered Oct 28 '22 14:10

indragie


I got the same problem with the same error when I tried to segue from a regular content view controller (ie. no problem segueing from a tab controller or a nav controller).

Fortunately I found a way to circumvent this by inserting a nav controller between the VC and the split view controller. In other word, segue from the VC to a nav controller, then draw a relationship connection between the nav controller and the split view controller. In this way, instantiating a split view still requires no coding.

like image 28
Hampden123 Avatar answered Oct 28 '22 15:10

Hampden123


Of course u can use UISplitViewController without using it as root view controller. In my project, I use it like this:

  1. Show my own viewcontroller in modal method:
[self presentModalViewController:mainViewController animated:YES];
  1. In the mainViewController, I have
UISplitViewController *splitViewController;

and in - (void)viewDidLoad, set the splitViewController.view to mainViewController.view

splitViewController.viewControllers = [NSArray arrayWithObjects:masterNavigationController, detailNavigationController, nil];
self.view = splitViewController.view;
like image 32
xi.lin Avatar answered Oct 28 '22 16:10

xi.lin


The UISplitController CAN BE installed under UITabBarController. I do it. Just use search on this forum - I found at least one good software sample.

like image 20
Adrenalinevictim Avatar answered Oct 28 '22 14:10

Adrenalinevictim