MKMapView calling didSelectAnnotationView

强颜欢笑 提交于 2020-01-02 07:25:07

问题


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?


回答1:


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.




回答2:


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.




回答3:


Swift 2.1:

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)



回答4:


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

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




回答5:


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];


来源:https://stackoverflow.com/questions/8092569/mkmapview-calling-didselectannotationview

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!