In which case that mapView:viewForAnnotation: will be called?

旧巷老猫 提交于 2019-11-28 01:35:57

问题


Now I want to add a static pin annotation on map in my iOS app.

But I just want to know if the delegate method mapView:viewForAnnotation: will be called.

In the Apple documentation, it is said that

 When it needs an annotation view, the map view calls the mapView:viewForAnnotation:    method of its delegate object. 

I have read several tutorials from Internet and official documentation from Apple. And I still don't when this method will be called.


回答1:


Whenever you call addAnnotation method - (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id < MKAnnotation >)annotation gets called. Have look at the screenshot.

You can find this on MKMapView Class Reference

P.S. Put breakpoints at addAnnotation call and - (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id < MKAnnotation >)annotation you will see the flow of function call easily.




回答2:


Obviously MKMapView at least will call mapView:viewForAnnotation: when it will need to display your MKAnnotationView to the screen.



来源:https://stackoverflow.com/questions/9442830/in-which-case-that-mapviewviewforannotation-will-be-called

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