title: How can a modal view controller be dismissed if the presenting view controller is changed?
body: <p>I am presenting a modal view controller on the iPad which changes the presenting view controller while presented.  For example:</p>
  
  <ol>
  <li>A view controller VC presents the modal view controller when the user selects a cell in a table view.</li>
  <li>The user selects an item on the modal view controller and another VC instance is opened in place of the first.  Importantly, the view controller instance replacing the first is of the same type.</li>
  <li>The modal view controller cannot be dismissed or an <code>EXC_BAD_ACCESS</code> exception occurs.</li>
  </ol>
  
  <p>The failing dismiss is understandable: the presenting view controller is no longer available.  Basically, how would I dismiss this presented modal view controller from a different presenting view controller?</p>
  
  <p>The code I already have is:</p>
  
  <p>ViewController1.m</p>
  
  <pre><code>- (void)showModalViewController:(UIViewController *)viewController
  {
      UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:viewController];
      navigationController.modalPresentationStyle = UIModalPresentationFormSheet;
      viewController.navigationItem.rightBarButton = [[UIBarButton alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(dismissModalViewController)];
      [self presentViewController:navigationController animated:YES completion:nil];
  }
  
  - (void)dismissModalViewController
  {
      [self dismissViewControllerAnimated:YES completion:nil];
      [self.tableView deselectRowAtIndexPath:[self.tableView indexPathForSelectedRow] animated:YES];
  }
  </code></pre>