In my app, I switch between views modally. My problem is, when I move from the first viewController to the second, it works. When I dismiss the second view for the first time, that also works. Where is the problem, you say? It’s coming. When I move from the first viewController to the second a second time, it works again. Just as it should. Yet when I try to dismiss the second viewController the SECOND time, I get an EXC_BAD_ACCESS error on the
[self dismissModalViewControllerAnimated:YES];
line.
Why does it crash the second time, but never the first time?
EDIT ONE:
This error happens no matter which viewController I switch to:
If I move from A to B, then back to A, then to B, then try to go back to A: crash
If I move from A to C, then back to A, then to C, then try to go back to A: crash again
EDIT TWO:
I create/show the view controller with this code:
MapView *controller = [[MapView alloc] initWithNibName:@"MapView" bundle:nil];
controller.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentModalViewController:controller animated:YES];
Should I be releasing this object after its creation?
Problem solved. Offending line of code was being used earlier for the transition I was using before I used modal views, and I forgot to remove it. Win.
Typically, an
EXC_BAD_ACCESSerror means you are trying to reference a deallocated object, i.e. you are over-releasing something. Check back through your memory management, maybe run the Build/Build and Analyze tool.And yes, you should call
[controller release];after presenting the viewcontroller modally.