Can I use a UINavigationController as the detail view of a UISplitViewController?

Posted by B Sweigard on Stack Overflow See other posts from Stack Overflow or by B Sweigard
Published on 2010-09-21T17:07:07Z Indexed on 2011/01/16 14:53 UTC
Read the original article Hit count: 120

Filed under:

I'm running into a problem with an iPad app where I would like to have UINavigationControllers in both of the views within a UISplitView. I've looked through other similar questions here, but most link to a tutorial online that doesn't completely solve the problem. Here's a 2-minute walkthrough to re-create the problem I'm having:

  1. Create a New Project in XCode, starting from the Split View-based Application template.
  2. Add the following NSLog statement as the first line within the DetailViewController's willHideViewController method:

    NSLog(@"toolbar: %@", toolbar);

If you run the application now, the log will show that the DetailViewController's toolbar is alive and well. Now...

  1. Open MainWindow.xib and expand the SplitViewController.
  2. Drag a Navigation Controller from the library on top of the DetailViewController.
  3. Expand the new Navigation Controller and change the class of the UIViewController within to a DetailViewController.
  4. Ctrl-drag from the SplitViewController to the DetailViewController and assign it as the delegate.
  5. Save MainWindow.xib and run the app again.

At this point, the detail view has a navigation bar and an empty toolbar. If you view the logs, you should find that the toolbar is null. Why is this? Am I missing some sort of connection in Interface Builder? Is the navigation bar the problem for some reason?

Unlike the tutorial at http://www.cimgf.com/2010/05/24/fixing-the-uisplitviewcontroller-template/, I would like to keep both the navigation bar and the toolbar (preferably with the toolbar at the top when in portrait and not visible when in landscape), so that I still have a functional "Back" button when the iPad is in portrait orientation.

Does anyone have any suggestions for fixing this problem? An example project with this sort of set-up would be ideal.

© Stack Overflow or respective owner

Related posts about ipad-splitview