Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 314
dannail Avatar asked Feb 25 '12 09:02

dannail


2 Answers

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

enter image description here

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.

like image 162
rohan-patel Avatar answered Oct 12 '22 23:10

rohan-patel


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

like image 24
ivanzoid Avatar answered Oct 12 '22 23:10

ivanzoid