I have a MKMapView. I added a UITapGestureRecognizer with a single tap.
I now want to add a MKAnnotationView to the map. I can
Why not just add UITapGestureRecognazer in viewForAnnotation, use annotation's reuseIdentifier to identify which annotation it is, and in tapGestureRecognizer action method you can access that identifier.
-(MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id)annotation {
MKAnnotationView *ann = (MKAnnotationView*)[mapView dequeueReusableAnnotationViewWithIdentifier:@"some id"];
if (ann) {
return ann;
}
ann = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"some id"];
ann.enabled = YES;
UITapGestureRecognizer *pinTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(pinTapped:)];
[ann addGestureRecognizer:pinTap];
}
-(IBAction)pinTapped:(UITapGestureRecognizer *)sender {
MKAnnotationView *pin = (MKPinAnnotationView *)sender.view;
NSLog(@"Pin with id %@ tapped", pin.reuseIdentifier);
}