SMCalloutView; clicking on Annotation represents a calloutview but disappears immediately

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{
 //code omitted

 // create our custom callout view
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) {


        // apply the MKAnnotationView basic properties
        self.calloutView.title = annotationView.annotation.title;
        self.calloutView.subtitle = annotationView.annotation.subtitle;

        // Apply the MKAnnotationView desired calloutOffset (from the top-middle of the view)
        self.calloutView.calloutOffset = annotationView.calloutOffset;

        // create a disclosure button for comparison
        UIButton *disclosure = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
        [disclosure addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(disclosureTapped)]];
        self.calloutView.rightAccessoryView = disclosure;

        // iOS 7 only: Apply our view controller edge insets to the allowable area in which the callout can be displayed.
        if (floor(NSFoundationVersionNumber) > NSFoundationVersionNumber_iOS_6_1)
            self.calloutView.constrainedInsets = UIEdgeInsetsMake(self.topLayoutGuide.length, 0, self.bottomLayoutGuide.length, 0);


        // This does all the magic.
        [self.calloutView presentCalloutFromRect:annotationView.bounds inView:annotationView constrainedToView:self.map animated:YES];
    }
}

- (void)mapView:(MKMapView *)mapView didDeselectAnnotationView:(MKAnnotationView *)view {

    [self.calloutView dismissCalloutAnimated:YES];
}
+4

All Articles