Hi guys! I'm having some problem with MKMapView / annotations / UINavigationController. Basically, i manage my views using a UINavigationController; one of my view contains an MKMapView and i add annotations on it (10 to 200) using the addAnnotations method.
Everything is working fine except for one thing : if i navigate "too fast" on my UINavigationController, the iphone simulator crashes, receiving an "EXC BAD ACCESS" signal. For example, if i load my view containing the MKMapView and immediatly press the "Back" button from the UINavigationController navigation bar, i get the signal. I figured that the problem was with the addAnnotations method : when my MKMapView is loaded, i add annotations to it but it looks like everything is done asynchronously. If i wait like a second before pushing the "Back" button, i get no error but if i'm too fast, it crashes. I get no error at all if i remove the addAnnotations line. I guess it's because my view is released by the UINavigationController BEFORE the addAnnotations method got the job done.
Any good solution to this? I don't want the user to wait (displaying a loading view for example); i guess the solution might be a better memory management but i don't see how i could do this.
if(DEBUG_MODE) { NSLog(@"Creating array of placemarks : begin"); }
self.placemarkCache = [[NSMutableArray alloc] init];
// Loading placemarks for a placemark dictionary
NSArray *sortedKeys = [[self.placemarkDictionary allKeys] sortedArrayUsingSelector:@selector(compare:)];
for (id key in sortedKeys) {
MyPlacemark *currentPlacemark = [self.placemarkDictionary objectForKey:key];
[self.placemarkCache addObject:currentPlacemark];
[currentPlacemark release];
}
if(DEBUG_MODE) { NSLog(@"Creating array of placemarks : done"); }
if(DEBUG_MODE) { NSLog(@"Adding placemarks : begin"); }
[self.mapView addAnnotations:self.placemarkCache];
if(DEBUG_MODE) { NSLog(@"Adding placemarks : done"); }
On this example, i get the "Adding placemarks : done" message before anything get displayed on the map.