title: UIViewControllerHierarchyInconsistency in 64 bit iOS device
body: <p>I am developing an iPad application which has a single view controller (called as ContentViewController) with 3 different views in it.</p>
  
  <ol>
  <li>Slider view - opens from bottom, which has list of icons in it. Based on selecting a icon, I have to load a view controller in Content View </li>
  <li>Control view - left side of the screen with few buttons and text </li>
  <li>Container view - This covers large part of the screen, where I want to load view controllers based on the selection of an icon from slider</li>
  </ol>
  
  <p>This is how I implemented it</p>
  
  <p>At application start (for the first time), I normally load home view controller in Container View, which has table view with application related items. Every view controller is inside a navigation controller and I load that navigation controller in the container view</p>
  
  <p>When I select a icon in the slider view, I am loading a view controller. </p>
  
  <p>The following is the code that I implemented to do this stuff in a view controller with name ContentViewController:</p>
  
  <pre><code>- (void) itemSelected: (UIViewController *) viewController
  {
     // I am storing view controller in a instance variable currentViewController. The currentViewController is declared as @property (nonatomic , strong) UIViewController *currentViewController under @interface in header file
     if(_currentViewController == nil)
     {
        // This part of code gets executed for the first time, when there is no view controller available in ContainerView
        _currentViewController = viewController;
        [self addChildViewController:_currentViewController];
        [self.containerView addSubview:_currentViewController.view];
     }
     else if(_currentViewController != viewController)
     {
         // If a view controller is already opened in Container View and when I click a icon from the slider, this par of code is getting executed
         [self addChildViewController:viewController];
         [self transitionFromViewController:_currentViewController
                        toViewController:viewController
                                duration:0
                                 options:UIViewAnimationOptionTransitionNone
                              animations:^{}
                              completion:^(BOOL finished){
                                  [_currentViewController removeFromParentViewController];
                                  _currentViewController = viewController;
                                  [_currentViewController   didMoveToParentViewController:self];
                              }
       ];        
      }
  }
  </code></pre>
  
  <p>The code mentioned above is working fine in iPad2 and iPad3, which are 32 bit device. But when I run this application on iPad Air (64 bit device), it is crashing in transitionFromViewController throwing following error:</p>
  
  <pre><code>Terminating app due to uncaught exception 'UIViewControllerHierarchyInconsistency', reason: 'child view controller:&lt;UINavigationController: 0x136d76130&gt; should have parent view controller:(null) but actual parent is:&lt;ContentViewController: 0x136d39680&gt;'
  *** First throw call stack:
  (0x183642950 0x19001c1fc 0x183642890 0x186688f00 0x18661484c 0x186613ff4 0x10009a224 0x1001104c8 0x18673d798 0x1867fe234 0x186692470 0x1865fe4a4 0x1836030a8 0x183600330 0x1836006bc 0x1835416d0 0x1891ddc0c 0x186672fdc 0x100058028 0x19060faa0)
  libc++abi.dylib: terminating with uncaught exception of type NSException
  </code></pre>
  
  <p>I tried various options like removing transitionFromViewController and replacing with following code:</p>
  
  <pre><code>    [_currentViewController willMoveToParentViewController:nil];
      [_currentViewController removeFromParentViewController];
      _currentViewController = firstView;
      [_currentViewController didMoveToParentViewController:self];
  
      [self addChildViewController:_currentViewController];
      [self.containerView addSubview:_currentViewController.view];
  </code></pre>
  
  <p>But it again crashed in last line [self.containerView addSubview....] with same error mentioned above in iPad Air. I am not sure how to proceed and I don't why this issue happens only with 64 bit device. Could someone please help me on this.</p>
  
  <p>Thanks in advance!</p>
  
  <p>Vignesh</p>