0
votes

I present a modalViewController that is actually a navigation controller with one view, and a custom navigation bar. The modal view appears fine as expected, but when I attempt to remove it from view using [self dismissModalViewControllerAnimated:YES], I am hitting a "-[UINavigationController modalViewController]: message sent to deallocated instance". Can't seem to figure this out. Any ideas?

Instantiating the ModalViewController:

    // Make a navigation controller and add the view inside it
    MyViewController *evc=[[MyViewController alloc] initWithNibName:@"MyViewController" bundle:nil];
    //UINavigationController *nvc = [[UINavigationController alloc] initWithRootViewController:evc];
    UINib *nib = [UINib nibWithNibName:@"UINavigationBarWithBackgroundImage" bundle:nil];
    UINavigationController *nvc = [[nib instantiateWithOwner:nil options:nil] objectAtIndex:0];
    [nvc setViewControllers:[NSArray arrayWithObject:evc]];
    evc.delegate=self;
    [evc release];
    [self presentModalViewController:nvc animated:YES];
    [nvc release];

and trying to remove it. This is where the error comes in:

    [self dismissModalViewControllerAnimated:YES]; 
2

2 Answers

0
votes

Not sure about this, but try it anyway:

Remove

[nvc release]

and see if

[self dismissModalViewControllerAnimated:YES];

now works.

0
votes

Is there a reason you are loading two seperate nibs to show this modal? You do not need to load a nib containing a navigation controller to get this working.

Try something like this:

// Make a navigation controller and add the view inside it
MyViewController *evc= [[MyViewController alloc] initWithNibName:@"MyViewController" bundle:nil];

UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:evc];

evc.delegate=self;

[self presentModalViewController:navController animated:YES];

[evc release];
[navController release];