title: Dismissing iPad modal view messes up the UISplitView panels
body: <p>The premise is remarkably simple: I want to display a modal view in an iPad app that uses a UISplitViewController.</p>
  
  <p>The view hierarchy is straight-forward:</p>
  
  <pre><code>                                              /- TableViewController1
                       /- root:TabBarController -- TableViewController2
  SplitViewController -
                       \- detail:CustomViewController
  </code></pre>
  
  <p>When I click on one of the table cells in TableViewController1, I open a modal view:</p>
  
  <pre><code>- (void)tableView:(UITableView *)tv didSelectRowAtIndexPath:(NSIndexPath *)ip {
    UIViewController *vc = [[MyModalClass alloc] init];
    UINavigationController *nc = [[UINavigationController alloc]
                                  initWithRootViewController:vc];
    nc.modalPresentationStyle = UIModalPresentationFormSheet;
    nc.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
    [self presentModalViewController:nc animated:true];
    [nc release];
    [vc release];
  }
  </code></pre>
  
  <p>This works just fine: the view appears. The problems start when I try to dismiss it in any orientation other than landscape.</p>
  
  <p>In ModalViewController, the following method is triggered by a UITabBarButton in the navigation bar:</p>
  
  <pre><code>- (void) closeButtonInNavBarWasClicked:(id)sender {
    [self dismissModalViewControllerAnimated:true];
  }
  </code></pre>
  
  <p>And THIS is where the problems start.</p>
  
  <p>When this code is called, the modal view disappears, BUT: the TabBarController (the split view's root view) is suddenly rotated and resized. The content is suddenly sideways, and partially covers the details view. The details view isn't resized to be smaller, it's just partially covered by the root view.</p>
  
  <p>The only situation where this problem doesn't appear is when I tap on the TableViewController1 cell when the app is in portrait mode. Despite the root view being in a popover (which could be an ample source of bugs), everything works fine.</p>
  
  <p>Some things I have already tried, with no success:</p>
  
  <ul>
  <li>Dump the tab bar, just display TableViewController1 as the root controller of the split view</li>
  <li>Create a delegate protocol so that the parent TableViewController1 dismisses the modal view rather than the MyModalClass view itself.</li>
  <li>Presenting/dismissing the modal view on TableViewController1.splitViewController actually makes things worse: the view doesn't even appear.</li>
  <li>Sacrificing several goats also did not help.</li>
  </ul>
  
  <p>I would hugely appreciate any input on this issue.</p>