UIViewControllerHierarchyInconsistency when trying to present a modal view controller UIViewControllerHierarchyInconsistency when trying to present a modal view controller xcode xcode

UIViewControllerHierarchyInconsistency when trying to present a modal view controller


This happened to me already twice in the newest Xcode release.In both cases I needed to make changes to the UIViewController's XIB file (In you case it would be MapViewController.xib:

BEFORE:

enter image description here

  1. Move main View out of View Controller's children:
  2. Remove View Controller from the XIB (it is not necessary since File's Owner should be of its Class already):

AFTER:

enter image description here


I had this problem when running Apple's example audio app MixerHost on the iOS 6 simulator.

The equivalent of the above fix, namely to edit the supplied MixerHostViewController.xib by dragging the View object to the top level, and discarding the now-empty ViewController that used to contain it, worked perfectly (though not before I'd spent hours working out what the underlying problem was, so I'm feeling done-over by Apple at the moment - seems they tightened something up but didn't bother to check if it broke their sample apps).


I had this problem when my Nib had a UIViewController in the file at top level. So loading from Nib created that UIViewController, then I tried to use it from my class, which was in the position of MapViewController in your code.

In my case the solution was simply to remove the UIViewController from my Nib file.