Whenever I try to present a UISplitViewController modally the application crashes. Thus it must allways be the root view controller. Can anyone confirm that?
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.
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.
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.
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.
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.
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.
Of course u can use UISplitViewController
without using it as root view controller.
In my project, I use it like this:
[self presentModalViewController:mainViewController animated:YES];
UISplitViewController *splitViewController;
and in - (void)viewDidLoad
, set the splitViewController.view
to mainViewController.view
splitViewController.viewControllers = [NSArray arrayWithObjects:masterNavigationController, detailNavigationController, nil];
self.view = splitViewController.view;
The UISplitController CAN BE installed under UITabBarController. I do it. Just use search on this forum - I found at least one good software sample.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With