4

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

hsn
  • 173
  • 2
  • 10
  • I just got the same error. I narrowed it down to my cast from UIView to EAGLView (EAGLView *eagl = (EAGLView *)self.view). I'm still not sure what's causing this... – Diamondo25 Sep 24 '12 at 07:39
  • i assumed that the issue was with UIPopoverController... but when i tried to do any action with the UIViewController BookTestDrive the breakpoint stops at these actions.... something is wrong... and i have no idea what is it – hsn Sep 24 '12 at 08:47
  • Same error for me after upgrading to ios 6. 'UIViewControllerHierarchyInconsistency', reason: 'A view can only be associated with at most one view controller at a time! View > is associated with . Clear this association before associating this view with .' – Dat Nguyen Sep 26 '12 at 15:03
  • I haven't figured out how to solve this issue... but i had to ignore that nib file i have created and create that view by code rather than with interface builder... and it worked... but still i would love to know how to solve that error. – hsn Sep 27 '12 at 05:28

2 Answers2

2

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.

Kieran Harper
  • 1,098
  • 11
  • 22
  • Thanks, i have followed your advice... i deleted the ViewController in the xib file and everything worked just fine. would love to know why this was changed in ios 6 – hsn Oct 02 '12 at 07:08
-1

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.

TakMan
  • 1
  • 1
  • 1
    I would take a look at your xib file in interface builder and see if it has both a view and controller located within it. when you select the view controller and look at the connections inspector, there should be a connection to the view located within the same xib file. – TakMan Oct 02 '12 at 20:47
  • actually what worked for me was that i deleted the view controller from the xib file and only had the view file... then all worked fine. – hsn Oct 06 '12 at 07:24