_resignRootViewController causes app to crash.

Posted by RickiG on Stack Overflow See other posts from Stack Overflow or by RickiG
Published on 2010-04-06T10:01:18Z Indexed on 2010/04/06 10:03 UTC
Read the original article Hit count: 378

[MainViewController _resignRootViewController]: message sent to deallocated instance 0x4ebfe50

This error happens when I try to pop my MainViewController Object from within it self:

- (void) switchToTableView { //a method on the MainViewController
    [self.navigationController popViewControllerAnimated:NO];   
    [[UIApplication applicationDelegate] switchToTableView]; //convenience method for the app delegate
}

The debugger stops at the [super dealloc] command in MainViewControllers dealloc method.

I do the exact same thing in the TripTableViewController, but here it never crashes.

MainViewController and TripTableViewController are handled in my AppDelegate like this:

- (void) switchToTableView {

    TripTableViewController *tripTableViewController = [[TripTableViewController alloc] init];
    [[self.navigationController navigationBar] setHidden:NO];
    [self.navigationController pushViewController:tripTableViewController animated:NO];
    [tripTableViewController release];

}

- (void) switchToScrollView {

    MainViewController *scrollView = [[MainViewController alloc] init];
    [[self.navigationController navigationBar] setHidden:YES];
    [self.navigationController pushViewController:scrollView animated:NO];
    [scrollView release];
}

I am trying to achieve that when the user goes from TripTableViewController to MainViewController; TripTableViewController is released/popped and visa versa for the MainViewController. I do not wish for the navigationController to make the decision about when to pop/cache/release them, this is why I try to do it from within it self.

I have not been able to find the _resignRootViewController mentioned anywhere. My guess is that it is a delegate message sent by a ViewController that resigns as rootViewController for a navigationController and that somehow it is called twice, once before MainViewCOntroller is released/popped and somehow again afterwards.

Have any one else seen this error message before? Google and the Apple Docs does not mention it?

How can I debug such an error?

Hope someone can guide me in the right direction on this one, Thanks:)

© Stack Overflow or respective owner

Related posts about iphone

Related posts about uinavigationcontroller