Im using SMCalloutView here for 'UICalloutView' for my annotations. It works when I click on the annotation, a callout appears. I can reject the leader by clicking on the same annotation again or on the map itself. However, strange behavior occurs in this scenario;
I select the annotation that represents the "SMCalloutView". Then I select another annotation (without clicking on the original annotation or on the map to reject it), and as a result, the original "SMCalloutView" disappears, but a new one appears and disappears immediately (blinking effect). I followed the example, there is not much documentation on github, but the coding example is pretty well explained, here is my code;
MapViewController.m
@interface MapViewController ()<MKMapViewDelegate,CLLocationManagerDelegate,SMCalloutViewDelegate>
-(void)viewDidLoad{
self.calloutView = [SMCalloutView platformCalloutView];
self.calloutView.delegate = self;
}
#pragma mark - MKMapView delegate methods
- (MKAnnotationView *)mapView:(MKMapView *)mv viewForAnnotation:(id <MKAnnotation>)annotation
{
if([annotation isKindOfClass:[MKUserLocation class]])
return nil;
NSString *annotationIdentifier = @"PinViewAnnotation";
SandwichAnnotationView *pinView = (SandwichAnnotationView *) [mv dequeueReusableAnnotationViewWithIdentifier:annotationIdentifier];
if (!pinView)
{
pinView = [[SandwichAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:annotationIdentifier];
pinView.canShowCallout = NO;
}
else
{
pinView.annotation = annotation;
pinView.canShowCallout=YES;
}
return pinView;
}
- (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)annotationView {
if (mapView == self.map) {
self.calloutView.title = annotationView.annotation.title;
self.calloutView.subtitle = annotationView.annotation.subtitle;
self.calloutView.calloutOffset = annotationView.calloutOffset;
UIButton *disclosure = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
[disclosure addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(disclosureTapped)]];
self.calloutView.rightAccessoryView = disclosure;
if (floor(NSFoundationVersionNumber) > NSFoundationVersionNumber_iOS_6_1)
self.calloutView.constrainedInsets = UIEdgeInsetsMake(self.topLayoutGuide.length, 0, self.bottomLayoutGuide.length, 0);
[self.calloutView presentCalloutFromRect:annotationView.bounds inView:annotationView constrainedToView:self.map animated:YES];
}
}
- (void)mapView:(MKMapView *)mapView didDeselectAnnotationView:(MKAnnotationView *)view {
[self.calloutView dismissCalloutAnimated:YES];
}