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
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.
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.
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.