0
votes

I'm very new to storyboarding (also pretty new to iOS programming in general). I'm trying to add a Master/Detail view to my storyboard for an iPad only app. Here's what I've got so far:

  1. A main Tab Bar Controller that drives the navigation for my app. This is working.
  2. I've added a Split View Controller object to the MainStoryBoard from the libraries.
  3. Ctrl+drag from my Tab Bar Controller to the Split View Controller, select Relationship Seque->view controllers. This successfully adds the Split View Controller as a new tab item (which is what I want).

But now when I run my app and click on the new tab item, is just opens the detail view without the master view showing anywhere. I obviously haven't added any data yet, I just want to make sure everything is working first. Will the master not show if it's emtpy? That's not how other table controllers have worked for me; they've all shown empty tables. Which is what I'm looking for here so I can proceed with wiring the detail up on the left.

The Split View Controller looks a little foreign to me, as the first controller says 'Detail View Controller' with segues to a Navigation Controller then Table View Controller for the master, then a simple View Controller for the Detail. All that makes sense to me except that entry point calling itself a Detail View Controller. Which is what shows when I run it with no master popover/left pane table.

Update: When I start with a Master-Detail Application template, the Split View Controller object has both the Master View Controller and the Detail View Controller shown in that main screen. So something is different when I just drag it from the library. How do I accomplish the same thing in on existing storyboard without using the template? I've wired quite a bit of the rest of the navigation up around the Tab Controller that I would prefer to not redo.

Thanks.

3

3 Answers

6
votes

It looks like UISplitViewController has been updated in iOS8.1 to allow usage beyond just as the root view of the application. I have successfully implemented a tab bar item that segue's to a UISplitViewController. Apple's own documentation sort-of confirms this through the use of one word: typically. Found in the class documentation for UISplitViewController:

When building your app’s user interface, the split view controller is typically the root view controller of your app’s window.

So Apple is being vague, but I would take this as it's ok to do it. And, I can confirm it works.

Now, there is something else you have to do to keep it from going to the detail view prematurely. I'm not going to re-hash the details, but read this post, subclass UISplitViewController then:

  1. In viewDidLoad: set the SplitViewController's delegate to self
  2. Add UISplitViewControllerDelegate to the protocol list
  3. Then implement splitViewController:collapseSecondaryViewController:ontoPrimaryViewController and return YES to the whole method or to the circumstances listed in the post below

UISplitViewController in portrait on iPhone shows detail VC instead of master

2
votes

You cannot use a Split View Controller as one item of a Tab Bar Controller.

See for example http://developer.apple.com/library/ios/#documentation/WindowsViews/Conceptual/ViewControllerCatalog/Chapters/SplitViewControllers.html

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

Update: This seems to be wrong as of Xcode 6.1 and iOS 7/8. See @headache's answer.

0
votes

Try to test without TabBarController. If the bug will occur again then in Xcode in File Inspector for storyboard (small file icon usually in the right corner of the screen) uncheck Use Size Classes. Somewhere in this site i saw similar bug and this answer, also i had the same situation but without tab bar controller.