iOS - Uisplitviewcontroller with Storyboard - Multiple Master Views and Multiple Detail Views

iOS - UISplitViewController with storyboard - multiple master views and multiple detail views

If the split view controller delegate was the detail view controller that had been replaced, this is the cause of the crash. The replaced detail view controller is being dealloc'd and so the split view controller delegate is no longer a reference to a valid object.

You can update the delegate in prepareForSegue:sender:. For example:

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:@"MySegue"]) {
UIViewController *destinationViewController = [segue destinationViewController];
if ([destinationViewController conformsToProtocol:@protocol(UISplitViewControllerDelegate)]) {
self.splitViewController.delegate = destinationViewController;
}
else {
self.splitViewController.delegate = nil;
}
}
}

Which view controllers you use for delegates is dependent on your view controller hierarchy. In the simplest case, any view controllers that are assigned to splitVC detail will probably need to be delegates. You may want to base them all on a common super class that handles the shared split view controller delegate logic.

UISplitView with Multiple Detail Views (with Storyboard)

Turns out you can use the interface builder to add NSObjects to View Controllers. Once I did that, I changed the NSObject's class to DFMSplitViewManager, set it as the SplitViewController's delegate, and it was pretty straight forward from there.

Split View App with Multiple Detail Views

There's actually a great tutorial by the BigNerdRanch on how to use UISplitViewControllers. Honestly, there's no difference between using them to push a different UIViewController as the Detail or Master viewController. They just need a reference to one another and when an event happens, you push a new viewController to one side or the other. I've attached a sample project below for you to reference.

sample project: link

Here's another tutorial on setting one up via Raywenderlich: link

Using Multiple Detail View Controller in Split View Controller

You can use a container view in one of the panes of the split view. I think the ideal way to structure this (though there are many) is to have the "main" side of the split manage what is shown on the detail side. You should use protocols to pass the data is you need to.

Swift UISplitViewController with multiple storyboards for Detail View

I found a solution, the trick is to remove the segue and use a storyboard reference like this:

storyboard reference

For testing and teaching purposes, I created a complete test project which is available from GitHub. This demonstrates the use of multiple storyboards for the detail view.

Update Nov 28: this solution works but requires iOS 9. It is perfectly possible to use another UIViewController as a DetailViewController (meaning the template can be used) as long as you remove the segue, implement tableView: didSelectRowAtIndexPath and use the code from the example. In the latter case, it also works on iOS 8.



Related Topics



Leave a reply



Submit