5

I'm trying to do a project for the iPad in which I'd like to utilized the split view controller. I'll be having different detail view controllers for each of the cells in the master view controller.

I saw one solution how to do this via storyboard segues in this site.

He basically linked each of his UITableViewCell to different detail view controllers. But I'd like to know if this is a "stable" or a "good" way of doing this. I mean, is it any better or as stable as doing it programmatically? What would be the consequences of doing his method, if there are any?

Here is the link to the solution I found

Community
  • 1
  • 1
aresz
  • 2,589
  • 6
  • 34
  • 51
  • I think it's a good approach. If you know the options in advance, you can ofcourse have static cells in Table View and then have separate segues to each Detail View. If you don't options in advance then you have to use Prototype Cells and then you have to use Generic Segues which needs to be triggered from code using performSeguewithIdentifier method. You may find my solution for similar problem here - http://swiftwala.com/multiple-detail-views – Sachin Palewar Nov 11 '14 at 13:43
  • Possible duplicate of [Splitview with multiple detail views using storyboarding. Seen an example/tutorial?](http://stackoverflow.com/questions/7993168/splitview-with-multiple-detail-views-using-storyboarding-seen-an-example-tutori) – jrc Oct 14 '15 at 22:07

1 Answers1

4

This is kind of a tricky one, even though it's an incredibly common use case.

1) One idea is to have an empty root view controller as your detail and it handles managing segues under the hood to quickly segue to the detail view you actually care about, utilizing the "replace" segue. This should "technically" fix having the "back" button at the top left and still allow you to pop to root and not have it show the empty controller. Haven't tested these though, so I'm not sure.

Edit: In Xcode 6, the "replace" segue is conveniently handled by a "show detail" segue which is used specifically for this type of view handling on Split View Controllers. I recommend using this method exclusively in new projects. See sample code.

2) The other idea is to have separate navigation controllers in your storyboard (one connected, the rest all stranded). One for each detail view type and tapping on the master menu will simply swap the navigation controller for the detail view to the one you care about.

Code similar to this in AppDelegate:

self.detailNavigationController = [self.masterNavigationController.storyboard instantiateViewControllerWithIdentifier:@"MyChosenNavigationControllerStoryboardId"];
self.splitViewController.viewControllers = @[self.splitViewController.viewControllers[0], self.detailNavigationController];
self.splitViewController.delegate = (id)self.detailNavigationController.topViewController;

The downside to this second way is that in memory tests, it doesn't appear that swapping a new nav controllers in frees up all of the memory that the old nav controller was using. So it's good to use for simple apps but not for anything crazy complex.

Travis M.
  • 10,930
  • 1
  • 56
  • 72
  • Sample code does not work with compact width devices: https://github.com/dstarsboy/TMMultiDetailSplitView/issues/2 Kind of defeats the purpose of use a split view controller. – lostintranslation Nov 04 '16 at 22:30
  • The question is marked iPad only and the question is specifically about the iPad and when you open the sample code, the app is not universal, it's locked in as an iPad app... Compact devices has nothing to do with anything asked or answered. However, I did just update the code to work on phones as well, hope it helps you. – Travis M. Nov 07 '16 at 16:16