My task is to uncheck the map annotation during the second press.
I did not find how to do this using mapView functions. So I used an article from stackoverflow and did this:
- (void)viewDidLoad { annotationTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(annotationTapRecognized:)]; annotationTap.numberOfTapsRequired = 1; annotationTap.delegate = self; } - (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view { [view addGestureRecognizer:annotationTap]; } - (void)mapView:(MKMapView *)mapView didDeselectAnnotationView:(MKAnnotationView *)view { [view removeGestureRecognizer:annotationTap]; } - (void)annotationTapRecognized:(UIGestureRecognizer *)gesture { NSArray *selectedAnnotations = self.viewMap.selectedAnnotations; for (MapAnnotation *annotationView in selectedAnnotations) { [self.viewMap deselectAnnotation:annotationView animated:NO]; } }
It seems to work correctly, but it is not. When I click on the annotation, the second callout disappears and appears again.
Any ideas?
Thanks in advance.
source share