Krishna
Krishna

Reputation: 378

Annotation Image is replaced by RedPushPin when long press on annotation

I have created Custom Annotation with following:

-(MKAnnotationView*)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation 
{
    MKPinAnnotationView *view = nil;
    if (annotation != mapView.userLocation)
    {
        view = (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:@"myAnnotationIdentifier"];
        if (!view) 
            view = [[MKPinAnnotationView alloc]initWithAnnotation:annotation reuseIdentifier:@"myAnnotationIdentifier"];

        if (((CustomAnnotation *)annotation).annotationType == 1)
        {
            view.image = [UIImage imageNamed:@"type1.png"];
            view.rightCalloutAccessoryView = nil;
            view.canShowCallout = YES;
        }
        else
        {
            view.image = [UIImage imageNamed:@"type2.png"];
            view.rightCalloutAccessoryView = nil;
            view.canShowCallout = YES;
        }
    }
return view;
}

Problem: When User press and hold for 2 seconds on any Annotation Image (type1 or type2), Image gets replaced by Red PushPin(Default for iPhone MKPinAnnotationView).

I want to avoid this replacement. How can I do so?

Upvotes: 8

Views: 2330

Answers (2)

ashraf
ashraf

Reputation: 21

Use didDeselectAnnotationView and didSelectAnnotationView and reselect the image as you did by :-

view.image = [UIImage imageNamed:@"type2.png"];

Upvotes: 2

user467105
user467105

Reputation:

Instead of declaring and creating an MKPinAnnotationView, declare and create a plain MKAnnotationView.

The MKPinAnnotationView likes to default to the red pin which is what it's for.

Upvotes: 23

Related Questions