简体   繁体   中英

UISplitViewController on iPad with Storyboards?

在此输入图像描述

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.

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.

主拆分目的地

细节拆分目的地

解

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

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"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM