1

I know this question was posted before, but answers I ´ve found are not according this case

The exception occurs after running an app wroten 2 years ago in Xcode 4.5.1.

This is:

exception 'UIViewControllerHierarchyInconsistency', reason: 'A view can only be associated with at most one view controller at a time! <UIView: 0xaa9c4f0; frame = (0 0; 320 367); autoresize = W+H; layer = > is associated with <TabledReservationListController: 0xaa89e80>. Clear this association before associating this view with <UIViewController: 0x9e9e310>.'

Then in several answers like this one

UIViewControllerHierarchyInconsistency when trying to present a modal view controller

suggest to remove the viewcontroller in the nib file like it can be seen on the question image.

The problem is that in this case , i don´t have the viewController, this is the nib file of TabledReservationListController:

TabledReservationListView.xib

And this is the part of the code where the app crashes:

- (void)viewDidLoad {
    [super viewDidLoad];

    [navigation setDelegate: self];
    [self createReservationListController];

    [reservationListController viewWillAppear: NO];

     // in this line below
    [[navigation topViewController] setView: [reservationListController view]];

    [reservationListController viewDidAppear: NO];

    [[self view] addSubview: [navigation view]];
    CGRect r = [[self view] frame];
    r.origin.y = 0;
    [[navigation view] setFrame: r];

    [reservationListController setNavigationController: navigation];
}


- (void)createReservationListController {
    TabledReservationListController *res_ =
        [[TabledReservationListController alloc] initWithNibName: @"TabledReservationListView"
                                                          bundle: nil];
    [self setReservationListController: res_];
    [res_ release];

    [[[self navigation] topViewController] setTitle: @"Available Tables"];
}

Maybe someone could help, regards.

Community
  • 1
  • 1
alejandro
  • 389
  • 2
  • 13

1 Answers1

1

You shouldn't call viewWillAppear and viewDidAppear. Those are supposed to be methods where the framework calls you.

Instead of trying to give the reservationListController's view to a different controller, you should push reservationListController.

Phillip Mills
  • 30,888
  • 4
  • 42
  • 57
  • Thanks, I will try that. The app is kind of complex and was coded by another person, i´m beginner in iOS. I think he tried to load different views with same structure (TabledReservationListController) in a property of ReservationListPresenterController, which is ReservationListController. Would be grotesque if I paste all the code here because of size. The problem started with Xcode 4.5 and UIViewControllerHierarchyInconsistency. – alejandro Nov 29 '12 at 13:14