Search code examples
iosxcodeuisplitviewcontrolleruisplitviewuisplitviewdelegate

UISplitView showDetailViewController: not working on a device


I have a home page and when a certain button is pressed, it takes you to a split view with a table on the left (master) side and a view showing details on the right (detail) side. The app is working fine on the simulator, but when I run on my iPad mini I get an error.

When the user clicks on a table cell in the left (master) view, I call:

DetailViewController *detail = [self.storyboard instantiateViewControllerWithIdentifier:@"detailViewController"];
detail.jobInfo = [_fetchedResultsController objectAtIndexPath:indexPath];
[self.splitViewController showDetailViewController:detail sender:self];

That updates the detail view in the simulator, but crashes and gives me the following error on a device:

'-[UISplitViewController showDetailViewController:sender:]: unrecognized selector sent to instance' 

Any suggestions on how to fix this?


Solution

  • To update the viewControllers property directly, do this:

    NSArray *vcs = @[self.splitViewController.viewControllers[0],detail];
    self.splitViewController.viewControllers = vcs;