user1418166
user1418166

Reputation: 11

MKMapView ignores annotations after unload&load (memory warning)

please help me with this obstacle. I have a MKMapView with about 200 annotations. When I tap one of them, a detail view is pushed into UINavigationController so the MKMapView gets hidden. During browsing the presented detail view, I get memory warning and the hidden view is unloaded. After I close the presented detail view, the view with MKMapView is loaded again, but no annotation is visible (except User Location blue bubble) and focus is reset to the default one. [mapView: viewForAnnotation:] doesn't get called.

Even if I remove all annotations in viewDidUnload and insert fresh ones in viewDidLoad, the MKMapView doesn't display them anyway, even though [mapView: viewForAnnotation:] gets called for every single one.

Any idea how to make it behave and keep the same visible map rectangle after unload & load? Thank you very much.

EDIT - RESOLVED! The problem was that in the initWithNibName, I was getting

map = (MKMapView*)[self.view viewWithTag:TAG_MAP];

and from that moment on, I worked just with the 'map' variable. But after the reload, the variable apparently pointed to an invalid object. So I moved the command above to the viewDidLoad and now it works a treat. Thanks Craig to pointing me to the good direction!

Upvotes: 1

Views: 533

Answers (1)

Craig
Craig

Reputation: 8294

Perhaps you're getting separated from the MKMapView or its delegate during the reload. You could look at fixing the memory warning, or change your map initialization code to be sure the same stuff is called during viewdidload as the initial load. Might be worth checking on viewDidLoad though, I think I heard it gets treated differently in iOS 6.

Upvotes: 0

Related Questions