iOS: UISplitViewController cannot be pushed to UINavigationController

Go To StackoverFlow.com

21

I have an XCode iPad project using a navigation controller. I tried to get a button to push a UISplitViewController to the navigation stack, but got this error:

Split View Controllers cannot be pushed to a Navigation Controller

Turns out UISplitViewController doesn't play nicely with UINavigationController. However, I still need to show the split view controller when this button is clicked. How do I do this? And, also important, how do I make a back button so the user can be returned to the navigation controller?

2012-04-05 00:38
by Theron Luhn


28

To display a SplitViewController you'll need to use setRootViewController. This is because a SplitViewController needs to be the root view controller.

From Apple's Documentation:

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. The panes of your split-view interface may then contain navigation controllers, tab bar controllers, or any other type of view controller you need to implement your interface.

To get back you'll need to use setRootViewController to go back to the earlier page. I ran into this problem when I converted my iPhone app to universal, and ended up using a navigation controller for the iPhone and setRootViewController for the iPad version. It's a bit of a bummer because you can't animate it nicely without a bit of fudging.

2012-04-05 00:57
by glenstorey
How would I use setRootViewController? Google tells me it's a method of UIWindow, but I can't figure out where to find a UIWindow instance - Theron Luhn 2012-04-05 16:29
You need to grab it as a property from your app delegate, like this: MyAppDelegate *appDelegate = (MyAppDelegate *)[[UIApplication sharedApplication] delegate]; and then [appDelegate.window setRootViewController:shareSelectViewController] - glenstorey 2012-04-05 19:58
thank you so much - Dmitry Khryukin 2013-04-22 22:44
Ads