MKAnnotation is not selectable in iOS5

My application places the button on the map and then selects its use of animation, so the user has a visual hint and can immediately read the title / subtitles. The following code works both in iOS4 and iOS5, but in iOS5 the annotation is not automatically selected unless I changed the animation to NO in the selectAnnotation method.

Any ideas why?

MapAnnotations *pushpin = [[MapAnnotations alloc] initWithCoordinate:coordinate]; pushpin.title = [selectedStation valueForKey:@"name"]; pushpin.subtitle = [selectedStation valueForKey:@"address"]; [stationMap addAnnotation:pushpin]; [stationMap selectAnnotation:pushpin animated:YES]; [pushpin release]; pushpin = nil; 
+5
source share
1 answer

I’m not sure why this will work earlier, but the animation probably requires the creation and preparation of annotations, which is unlikely immediately after adding the annotation.

What you can do is move the selection to the didAddAnnotationViews delegate didAddAnnotationViews , which should work on all versions of iOS:

 - (void)mapView:(MKMapView *)mapView didAddAnnotationViews:(NSArray *)views { for (MKAnnotationView *av in views) { if ([av.annotation isKindOfClass:[MapAnnotations class]]) { MapAnnotations *pushpin = (MapAnnotations *)av.annotation; if (_this_pushpin_is_the_one_to_select) { [mapView selectAnnotation:av.annotation animated:YES]; break; //or return; } } } } 
+5
source

Source: https://habr.com/ru/post/909763/


All Articles