I have an app that navigates thru different views using the navigation controller. This is what I’m doing:
MapViewController *aMap = [[MapViewController alloc] initWithNibName:@"MapView"
bundle:nil ];
[self.navigationController pushViewController:aMap
animated:YES];
[aMap release];
At an user action, I want to go back to the first view. This is what I 开发者_高级运维did:
-(void)alertView:(UIAlertView *)alertView
didDismissWithButtonIndex:(NSInteger)buttonIndex
{
[self.navigationController popToRootViewControllerAnimated:NO];
}
When I press a button that call the bellow method, my app goes as expected to the first view. But the problem arises when I press the “Home button” and try to reopen the app. Then, the app crash giving the following error:
2010-12-23 14:33:18.504 test[4549:307] *** -[MapViewController respondsToSelector:]: message sent to deallocated instance 0x5c26320
I understand that I sending a message to an instance of the object that does not exist, but I don’t find where is this happening
Do you have any recommendation?
Something is trying to send messages to the MapViewController after it's been deallocated.
Are they any objects that reference it - is it the delegate for any of its subviews, or does it receive any notifications, or anything like that?
If so, you need to make sure you unsubscribe from any notifications in the controller's dealloc
method, and set any delegate
parameters (on other objects) that reference the controller to nil.
精彩评论