Reputation: 1538
In my master view I have 4 static table rows. 2 of these rows drill down into a detail view within the master view and the other 2 replace the contents of the detail view. I control what happens with the didSelectRowAtIndexPath() method by calling showViewController() and showDetailViewController() functions as appropriate:
- (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.row == 0) {
Master2TVC *m2tvc = [self.storyboard instantiateViewControllerWithIdentifier:@"master-2"];
[self showViewController:m2tvc sender:self];
} else if (indexPath.row == 1) {
Master3TVC *m3tvc = [self.storyboard instantiateViewControllerWithIdentifier:@"master-3"];
[self showViewController:m3tvc sender:self];
} else if (indexPath.row == 2) {
Detail2VC *d2vc = [self.storyboard instantiateViewControllerWithIdentifier:@"detail-2"];
[self showDetailViewController:d2vc sender:self];
} else if (indexPath.row == 3) {
Detail3VC *d3vc = [self.storyboard instantiateViewControllerWithIdentifier:@"detail-3"];
[self showDetailViewController:d3vc sender:self];
}
}
The template for the Master-Detail template creates a reference from the master view to the detail view:
self.detailViewController = (DetailViewController *)[[self.splitViewController.viewControllers lastObject] topViewController];
If I understand things correctly, this reference exists so that the master side can send messages to the detail side. In my case the class of my detail view will change (Detail3VC, Detail2VC, etc) so I've decided to remove this line and do the messaging another way; however, now when I load any of my new detail views and change the rotation of the iPad the App sometimes crashes with the error EXC_BAD_ACCESS.
From what I understand EXC_BAD_ACCESS usually means there is an object hanging around somewhere that shouldn't be. I have been unable to find anything in the Apple documentation that talks about having to change anything else when using showDetailViewController() call. In fact, I thought that the reason for using showDetailViewController() is so that the splitViewController manages all the details and you don't have to in your own classes.
Anyone can see the error here?
Upvotes: 1
Views: 1083
Reputation: 2459
I have confirmed the crash you encountered. It always, not sometimes, happens when changing iPad's rotation.
Anyway, it seems that we need to implement -targetDisplayModeForActionInSplitViewController:
of UISplitViewControllerDelegate
and return any value except UISplitViewControllerDisplayModeAutomatic
.
- (UISplitViewControllerDisplayMode)targetDisplayModeForActionInSplitViewController:(UISplitViewController *)svc {
return UISplitViewControllerDisplayModePrimaryOverlay;
}
Upvotes: 2