I have a view controller with MKMapView that calls
[self.mapView setRegion:region animated:YES]
which translates the mapping from A to B.
The view controller that contains MKMapView is installed as a delegate and in
- (void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated
I have a code that will call another setRegion: animated: in MKMapView so that the map automatically increases its new position.
Everything works fine if I popViewControllerAnimated: the view controller AFTER the MKMapView animation, pan and zoom are performed.
However, when I try popViewControllerAnimated: the current WHILE view controller, when MKMapView starts its animation, the application crashes with a message sent to the freed instance.
From the debugger views, I think MKMapView is trying to call a method from a popped up and freed delegate.
So i tried
[self.mapView setDelegate:nil]; self.mapView = nil;
in viewDidUnload with no luck. The app is still constantly crashing.
The only thing I could think of was to create a separate new delegate class and save this class from the parent view controller so that MKMapView has a delegate to call even after the view controller containing it is freed.
Why is this happening? Are there other "clean" options?
source share