I have different custom map annotations on my MKMapView, and when I create a custom view, I add an observer and turn off the default popup.
At the top of MapViewController.m:
static NSString* const ANNOTATION_SELECTED_DESELECTED = @"annotationSelectedOrDeselected";
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation {
[annotationView setEnabled:YES];
[annotationView setCanShowCallout:NO];
[annotationView addObserver:self
forKeyPath:@"selected"
options:NSKeyValueObservingOptionNew
context:ANNOTATION_SELECTED_DESELECTED];
return annotationView;
}
Then, in the observer function, I create a popover and show it:
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {
NSString *action = (NSString *)context;
if ([action isEqualToString:ANNOTATION_SELECTED_DESELECTED]) {
BOOL annotationSelected = [[change valueForKey:@"new"] boolValue];
if (annotationSelected) {
}
} else {
NSLog(@"Annotation deselected! But never pass here...");
}
}
My problem is when my popover is fired, if I want to select the same annotation, it just doesn’t work ... For example, if the observer state is still “activated”. Therefore, to select my annotation, I need to select another one, and then I can select it again ... This is annoying so that it is not possible to select the same annotation twice in a row.
Please help me! Thank.