Reputation: 3442
I have a MKMapView displaying some custom locations . Everything works fine until I press the go back button .
SearchViewController is my class name.
Sometimes I get :
[SearchViewController respondsToSelector:]: message sent to deallocated instance 0x73495f0
Other times :
[SearchViewController mapView:regionDidChangeAnimated:]: message sent to deallocated instance 0x7343f20
Or :
[SearchViewController mapView:didUpdateUserLocation:]: message sent to deallocated instance 0x7343f20
These functions are :
-(void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation
{
MKCoordinateRegion mapRegion;
mapRegion.center = mapViewHandler.userLocation.coordinate;
mapRegion.span.latitudeDelta = 0.2;
mapRegion.span.longitudeDelta = 0.2;
[mapViewHandler setRegion:mapRegion animated: YES];
}
- (void)mapView:(MKMapView *)mapView didDeselectAnnotationView:(MKAnnotationView *)view
{
//do nothing
}
This usually happens when I get into the view and then right back out.
Could you help me get rid of this bug ? I have the mapViewHandler
created in the .xib
file , and used [self.mapViewHandler setDelegate:self];
in viewDidLoad()
method.
Is there a way to stop everything from loading(requests,etc.) when I press the go back button and leave this view ?
Upvotes: 2
Views: 940
Reputation: 2336
When you "go back", your SearchViewController is being pulled off of the navigation stack and is getting deallocated. However, the MKMapView is still active and is trying to invoke delegate methods on your view controller which no longer exists. Try setting the mapView delegate to nil in your view controller dealloc or viewDidUnload method.
Upvotes: 4
Reputation: 533
You can set the delegate of the map view to nil in the dealloc method
Upvotes: 0