UIViewControllerHierarchyInconsistency worked in ios5 but not in ios6

丶灬走出姿态 提交于 2019-12-07 10:37:10

问题


I had a perfectly working project until i have updated to ios6.

when i tab on a bar item to show a popover with a view the app crashes...

here is the error i'm getting

    "reason: 'A view can only be associated with at most one view controller at a time! View <UIView: 0xaa7d730; frame = (20 0; 748 1024); autoresize = RM+BM; layer = <CALayer: 0xaa7d790>> is associated with <TYOFormViewController: 0xaa7d8b0>. Clear this association before associating this view with <TYOFormViewController: 0x14c68a70>.'"

and here is the method that declares the UIViewController and the UIPopoverController.

    - (IBAction)TestDriveTapped:(id)sender{
if (PopoverController != nil) {
    [PopoverController dismissPopoverAnimated:YES];
    self.PopoverController = nil;
}
if (self.PopoverController == nil) {
    UIViewController *bookTestDrive =[[TYOFormViewController alloc] initWithNibName:@"TYOBookTestDriveForm" bundle:nil];

   UIPopoverController *poc  = [[UIPopoverController alloc]
                           initWithContentViewController:bookTestDrive];

   [poc presentPopoverFromBarButtonItem:sender permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
     self.PopoverController = poc;
} else {
    if (PopoverController != nil) {
        [PopoverController dismissPopoverAnimated:YES];
        self.PopoverController = nil;
    }
}

}

The error says i have to clear the association with TYOFormViewController to associate it with TYOFormViewController.... How did this happen???

Would love your help with this issue... jstuck all day with it..

Thanks


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/12559792/uiviewcontrollerhierarchyinconsistency-worked-in-ios5-but-not-in-ios6

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