Oksana
Oksana

Reputation: 13942

MKMapView calling didSelectAnnotationView

I use MKMapView. On map I show clickable AnnotationViews. After click on AnnotationView, I push MyController to NavigationController. In MyController I click on the back button, after this my previous controller is show (do pop controller). When I click on AnnotationVIew in my previousController callback didSelectAnnotationView does not rased. Why it happened?

Upvotes: 4

Views: 4500

Answers (5)

Juan Boero
Juan Boero

Reputation: 6417

Swift:

By Apple documentation (press Cmd + Click over the class name):

// Select or deselect a given annotation.  Asks the delegate for the corresponding annotation view if necessary.
public func selectAnnotation(annotation: MKAnnotation, animated: Bool)
public func deselectAnnotation(annotation: MKAnnotation?, animated: Bool)
public var selectedAnnotations: [MKAnnotation]

So after performing all the actions on the selected annotation call:

self.yourMapView.deselectAnnotation(yourAnnotation, animated: true)

Upvotes: 2

Nagarjun
Nagarjun

Reputation: 6867

Once we click on annotation it will call

- (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view

on clicking outside of annotation it should trigger

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

but in my case i was overriding clicking outside annotation so i called method programmatically where ever needed:

[geoMapView deselectAnnotation:nil animated:NO];

Upvotes: 0

Soroush Shahhoseini
Soroush Shahhoseini

Reputation: 19

As Oksana said: it's because the annotation view is selected and you should deselect it.

You can use : [_mapView selectAnnotation:nil animated:NO];

Upvotes: 0

Oksana
Oksana

Reputation: 13942

It because when I click on annotation it annotation selected and when I click on this annotation again it does not call callback didSelectAnnotationView, because this annotation already selected.

Upvotes: 3

Minakshi
Minakshi

Reputation: 1433

Check whether you have added MKMapViewDelegate in .h file and seted the delegate in .m file

 mapView.delegate = self;

And still if it will not work check didSelectAnnotationView is properly written or not.

Upvotes: 2

Related Questions