0

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.

fr0man
  • 835
  • 3
  • 12
  • 27

3 Answers3

6

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

Community
  • 1
  • 1
headache
  • 128
  • 1
  • 8
2

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.

Martin R
  • 488,667
  • 78
  • 1,132
  • 1,248
  • Dang, no wonder I couldn't find any sample code. What I really need todo is have the tab controller navigation to a screen with side by side tables. Selecting a value on the left table needs to populate the right table. Is there an easy way to do that within the tab controller? Perhaps just a view controller with two table controllers? As I said, I am a total noob with iPad design patterns. – fr0man Aug 19 '12 at 16:49
  • @fr0man: I have never created such a design, so I cannot give good advice. – Martin R Aug 19 '12 at 16:59
  • In Xcode 6 you can definitely create a UITabBarController and each tab can be a UISplitViewController. It will also be backwards compatible with iOS 7 if you choose to do so. I've successfully done just that. So this answer isn't correct at least when working with Xcode 6 and compiling with iOS 8 SDK. – Jordan H Oct 30 '14 at 17:43
  • @Joey: Good to know, thanks for the feedback. Sadly, the above referenced "View Controller Catalog" has not been updated yet. – Martin R Oct 30 '14 at 17:48
0

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.