UIViewControllerHierarchyInconsistency worked in ios5 but not in ios6

I had a perfectly working project until I upgraded to ios6.

when I find a tab in a panel element to show a popover with an application crash view ...

here is the error i get

"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 a method that declares a UIViewController and a 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 that I need to clear the connection with TYOFormViewController in order to associate it with TYOFormViewController .... How did this happen ???

I would like to help you with this question ... jstuck all day with him ..

thanks

+4
source share
2 answers

I also had this when downloading a bunch of xib files. The solution was to go to the interface builder and delete any view controller objects with the same class name as the file owner. Therefore, in my case, these files now contain only the view and routines associated with the file owner - without controllers.

Something should change under the hood in iOS 6 when interpreting xib files.

+2
source

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

My fix was to clear the code, get rid of the creation of the manual view controller, and let iOS download it for me from 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 required.

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

-1
source

Source: https://habr.com/ru/post/1435845/


All Articles