UISplitViewController on iPad with Storyboards?
Asked Answered
B

3

6

enter image description here

In Xcode, how can I create a simple iPad application that uses Storyboards such that the DetailView controller is swapped out for each entry? Most examples that I've seen use the iPhone or they simply change the values in the same detail view controller.

I want to create the segues in Interface Builder from a static TableView Controller (with say 3 rows) where each row will load a different game detail view controller, which I would drag out and design in IB. Currently, when I connect a view controller with a segue, it replaces the navigation part of the UISplitViewController. In other words, it's like I'm traversing a tree, and I need to tell IB that I'm at a root node and I should be changing the Detail View.

Barcelona answered 14/2, 2012 at 5:38 Comment(1)
For a Swift + iOS8 solution for this problem using Universal Storyboards you may like checking out my code - swiftwala.com/multiple-detail-viewsLanam
B
18

A good starting point for segues are Lectures 6 and 7 of Stanford's CS193p Fall 2011 class.

http://itunes.apple.com/us/itunes-u/ipad-iphone-application-development/id473757255

The instructor, Paul Hegarty, covers everything. However, he runs out of time before the end of class to answer this question. He does include the source with the final solution in the file: Psychologist with Dr Pill.zip.

http://www.stanford.edu/class/cs193p/cgi-bin/drupal/downloads-2011-fall

Basically, all that needs to be done for this question is to Ctrl-drag from each UITableCell to the respective game detail view controllers then select the Replace segue. There is one more step because the view controller will shrink because by default Xcode thinks that you want to replace the master controller. For each of the segues, select the connection line and in the Attributes inspector then change the Destination from "Master Split" to "Detail Split". At this point, you can test with the popover, without writing any code.

Master Split Destination

Detail Split Destination

Solution

Barcelona answered 9/4, 2012 at 2:19 Comment(5)
I'm having a problem with your solution. When you do this, it replaces the Detail Navigation Controller so there is no way to call back the popup.Fabri
Did you look at episode 7 of the Stanford class? This could be happening if you don't set the delegate properly.Barcelona
Actually, this example should be helpful: github.com/toddwbates/MultipleMasterDetailViewsBarcelona
Wowww... thanks for this answer dude. it saved the day for me :) Thanks a tonSeveral
Note that if you're using iOS 8 adaptive segues, it's called "Show detail (e.g. Replace)" and there's no need to set the destination to the detail split - there is no "Destination" option. Works great!Availability
S
1

Apple has provided sample code of a more general solution to the problem of how to swap out different detail views based on what is selected in the master view. The Apple example code accomplishes this by introducing a custom implementation of the UISplitViewControllerDelegate protocol:

https://developer.apple.com/library/ios/samplecode/MultipleDetailViews/Introduction/Intro.html

Sachi answered 23/10, 2013 at 14:2 Comment(0)
G
0

Hard to describe without pictures but: have a navigation controller as the master. Then hang each detailview off this with a named segue that replaces. Then you need a bit of code. In you master viewcontroller inside didSelectRowAtIndexPath, you need a switch statement based on indexpath.row and in each row call detailview performSegueWithIdentifier:@"the row you want"

Gombroon answered 23/3, 2012 at 6:52 Comment(2)
You can always add a picture to your answer :) probably quite a good way to win the bounty too!Loireatlantique
I added a picture. When I click on "Game #2", how do I create the segue to the Game 2 view controller, for example? Can I do this with Ctrl-drag segues from my UITableViewCells?Barcelona

© 2022 - 2024 — McMap. All rights reserved.