UIViewControllerHierarchyInconsistency worked in ios5 but not in ios6

▼魔方 西西 提交于 2019-12-05 16:13:47

I also had this happening when loading a bunch of xib files. The solution was to go into interface builder and delete any view controller objects with the same class name as file's owner. So in my case those files now contain only the view and the subviews, connected to file's owner - no controllers.

Something must have changed under the hood in iOS 6 when interpreting xib files.

iOS 6 changed the handling of View/Controllers slightly. This broke the popovers with xib loaded content in my app, and I was getting the same error as you. I found that I had manually allocated and initialized the view controller code in my original (broken version) and then manually assigned the view to it (in effect ignoring the controller in the xib). Worked fine in previous iOS versions, but not 6.0.

My fix was to clean up the code, get rid of the manual view controller creation, and let iOS load it for me from the xib.

  NSArray* nibViews =  [[NSBundle mainBundle] loadNibNamed:@"InfoView" owner:self options:nil];
  InfoView* infoView = [ nibViews objectAtIndex: 0];
  InfoViewController *infoViewController = [ nibViews objectAtIndex: 1];

No assignment from the controller to the view (or vice versa) is necessary.

I would recommend looking through both your popover controller and the content controller to look for any direct assignments between controller and view.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!