title: parentViewController returning incorrect parent
body: <p>I am creating a modal view (OnlinePeerBrowser) from within a navigation subview (ConnectionScreen). I need to reference methods from the parent view of the Modal view. For some reason, the modal view believes it's parent is the rootView and not the view I created the modal from.</p>
  
  <p>What am I doing wrong?</p>
  
  <p>My code to create the modal view</p>
  
  <pre><code>@implementation ConnectionScreen {
  - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
      self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
      if (self) {
      self.title = @"ConnectionScreen";
      }
      return self;
  }
  
  ...
  
   - (void)peerPickerController:(GKPeerPickerController *)picker didSelectConnectionType:(GKPeerPickerConnectionType)type {
  if (type == GKPeerPickerConnectionTypeOnline) {
       OnlinePeerBrowser *controller = [[OnlinePeerBrowser alloc] 
                                       initWithNibName:@"OnlinePeerBrowser" bundle:nil];
      [self presentModalViewController:controller animated:YES];
      NSLog(@"my current view title: %@", [self title]);
      NSLog(@"parent of the controller title: %@", [controller.parentViewController title]);
  </code></pre>
  
  <p>The output is:</p>
  
  <pre><code> my current view title: ConnectionScreen
   parent of the controller title: Home
  </code></pre>
  
  <p>The modal view is being created and presented as a ModalViewController from within a ConnectionScreen instance. Why is it using the root window as the parent?</p>
  
  <p>------- More on this -----------
  I filed a bug with Apple thinking I was smart ;). They actually identified an issue with my code with pushing the nav controller (Scroll to bottom to see). I don't see what am I doing wrong. They also made sure this type of thing doesn't happen in 5.0 with gracefully exiting addressing an API change as Vinnie states below. </p>
  
  <p>If anyone can see what I am doing wrong with the view pushing below, I would appreciate it.
  ------- More on this -----------</p>
  
  <p>just received a response from Apple after filing a bug report on the ModalViewController for iOS development.  I am trying to deciper their response. 
  (Note the support response says confidential. Since you are all registered Apple developers, I thought it would be ok to share.)</p>
  
  <p>From the response below, I can't tell if they are they saying that my approach to creating the navigation controller and pushing the root view is wrong, or if they admitting to the bug and stating that they reconciled this in iOS 5.</p>
  
  <p>Here is the code I submitted to repeat the 'bug'.</p>
  
  <p>The response to the bug I filed:</p>
  
  <hr>
  
  <h2>Bug Title: Modal view has the incorrect parent</h2>
  
  <p>Steps to Reproduce:
  Create a navigation controller
  Push a view controller with the title 'Home'
  Create a button on the 'Home' view controller that pushes another view controller 'NewView'
  On 'NewView' create a button that pulls up a modal view
  In that modal view call self.parentViewController.title</p>
  
  <p>Expected vrs Actual Results:
  The parent title of the modal view should be NewView; however, it shows that the parent view of the modal view is Home.</p>
  
  <p>Notes:
  My workaround is to set a property on the modal view, myParent, prior to making the modal view visible.</p>
  
  <hr>
  
  <p>Their response</p>
  
  <hr>
  
  <p>Engineering has determined that this issue behaves as intended based on the following information: </p>
  
  <p>This test application will exit with a UIViewControllerHierarchyInconsistency in 5.0. The applicationDidFinishLaunching method is highly suspect (and the cause of the 5.0) exception. The window's root view controller is being pushed as the child of a view controller whose view is then added to the window.</p>
  
  <p>This is likely causing of all sorts of inconsistencies, hence why we now raise the issue on 5.0. Note that in 5.0, parentViewController no longer returns the modal presenter. We added the method presentingViewController to cover this case. parentViewController is now reserved to indicate a containment relationship between view controllers.</p>
  
  <hr>
  
  <p>The code they claim is suspect:</p>
  
  <ul>
  <li>(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions</li>
  </ul>
  
  <p>{</p>
  
  <pre><code>// Override point for customization after application launch.
  
  self.navigationController = [[UINavigationController alloc] init];
  
  self.window.rootViewController = self.viewController;    
  
  [self.navigationController pushViewController:self.window.rootViewController animated:NO];
  
  // Add the navigation controller's view to the window and display.
  
  [self.window addSubview:self.navigationController.view];
  
  [self.window makeKeyAndVisible];
  
  return YES;
  </code></pre>
  
  <p>}</p>