IOS - UISplitViewController with storyboard - some basic views and some detailed views

I am trying to build an iPad application using the UISplitViewController and storyboard. The main view begins with a navigation controller associated with a table view of 6 menu options. Each cell in the table pushes a different table view controller onto the navigation stack. This works great for the main view. Each view of the wizard has a list of tables that, when clicked, should display another view controller in the details pane. Currently, I have done this with segue set to "Replace" and "Detail Split", which works the first time a line is clicked, but as soon as you press another line in the main view or rotate the device, the application will shut down with EXC_BAD_ACCESS.

I am sure my problems are related to setting up a delegate for the UISplitViewController. I am confused as to how this should be used when I have several major VCs and several VCs with a few details. Where should the delegate code be placed - master or part? Should I implement UISplitViewControllerDelegate protocol events in each view controller?

Any help was appreciated.

+7
source share
1 answer

If the delegate of the split view manager has been replaced by the detail view controller, this causes a failure. The substituted detail view controller is deallocode and therefore the delegate of the split view controller is no longer a reference to a valid object.

You can update the delegate in the prepareForSegue: sender: file. 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 depend on your view manager hierarchy. In the simplest case, any view controllers that are assigned to splitVC parts should probably be delegates. You might want to base them on a common superclass that handles the delegation logic of a split view controller.

+16
source

All Articles