title: Dismissing modal view controller results in a black screen
body: <p>This is my view (controller) hierarchy:</p>
  
  <ul>
  <li><code>UITabBarController</code> (as the <code>rootViewController</code> of the app)</li>
  <li><code>UINavigationController</code> (as the <code>viewController</code> for one of the <code>tabBar</code> tabs)</li>
  <li><code>UIViewController</code> (as the <code>rootViewController</code> of the <code>UINavigationController</code>)</li>
  <li><code>UICollectionView</code> (as a subview)</li>
  <li><code>MyViewController.view</code> (as a section header view of the <code>UICollectionView</code>)</li>
  </ul>
  
  <p>And so, I need to present a modal view controller from <code>MyViewController</code>. I have tried doing it with</p>
  
  <pre><code>[self presentViewController:modalVC animated:YES completion:nil];
  </code></pre>
  
  <p>and although it worked, Xcode warned me that "Presenting view controllers on detached view controllers is discouraged", and rightly so, because the modalVC only fills the view of the collection view header, which is not full screen which I'm after.</p>
  
  <p>All other options that I have tried: </p>
  
  <pre><code>UITabBarController *tb = (UITabBarController *)self.view.window.rootViewController;
  [tb presentViewController:modalVC animated:YES completion:nil];
  
  or...
  
  UINavigationController *nc = (UINavigationController *)tb.selectedViewController;
  [tb presentViewController:modalVC animated:YES completion:nil];
  
  or...
  
  UICustomViewController *cv = (UICustomViewController *)nc.topViewController;
  [vc presentViewController:modalVC animated:YES completion:nil];
  </code></pre>
  
  <p>present the modalVC full screen as desired, however, when I dismiss the modalVC by calling</p>
  
  <pre><code>[self dismissViewControllerAnimated:YES completion:nil];
  </code></pre>
  
  <p>from within modalVC itself, modalVC indeed dismisses itself, but I am left with a <strong>black screen</strong>. A little debugging revealed that after dismissing modalVC, <code>self.view.window.rootViewController</code> becomes <code>nil</code>.</p>
  
  <p>Any idea why this is happening and how to resolve this?</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>This is an iPhone app. The black screen happens on both iOS7 and iOS8. Also, below is the method where I initiate <code>MyViewController</code></p>
  
  <pre><code>#pragma mark - UICollectionViewDelegate methods
  
  - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section {
  
      self.myViewController = [[MyViewController alloc] initWithNibName:NSStringFromClass([MyViewController class]) bundle:nil];
  
      return self.myViewController.view.frame.size;
  }
  </code></pre>