views:

238

answers:

3

Hi,

I've got a problem with a MKMapView, which is placed as a full-sized view in a UITabBarController at first position. Before the view will be shown, I add several annotations to the mapView. Everything just works fine.

When I change the tab (so that the mapView is out of view) and switch back to the tab with the mapView, all annotations are gone and it looks like the mapView is reset to default settings.

After debugging I found out, that when I switch back to the tab with the mapView, the reference to the mapView object points to a completly different address than before. I assume, that the mapView has been deallocated after leaving the tab, but I completely don't know why?

Thanks in advance for your replies!

Greetings, Sebastian

+2  A: 

Where are you putting your map annotations initialization code? In -viewDidUnload, you're probably setting mapView to nil, no? If so, make sure when the view is initialized again in -viewDidLoad, you're (re)adding the annotations.

If you have code, that would also help.

The coordinates of the annotations were loaded by an NSURLRequest. When the request is ready a NSNotification is posted and the annotations were handled by a method in the controller of the mapView and added to the map. But in the -viewDidLoad I don't reload them, maybe that is the error.
schaechtele
Where are you creating and executing the NSURLRequest? You should reload in -viewDidLoad. AFAIK, the view is (most of the time) set to nil when it goes offscreen (which is why it happens when you change tabs)
+1  A: 
CiNN
Is it possible that the -viewDidUnload isn't called? Because I put a breakpoint there, which was never reached.
schaechtele
then maybe you are instantiating the view twice..check where you are creating the controller
CiNN
A: 

I added the loading of the annotations to -viewDidLoad and think it works now as it should. Thanks for your help!

schaechtele