0

I only want to execute a method call when the user clicks on a annotation pin on the map. I read the Apple documentation but am still unsure of how I can do it (or if this is even possible).

For example, I have created a restaurant class with a 'Distance from current location' property and the instances are added to a mapview as annotations. I only want to trigger the calculateDistance method when the user clicks on an annotation (and the callout view is displayed).

Is there any way of doing this?

1 Answer 1

4

Override - (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view in your MapView delegate.

The MKAnnotationView contains a property annotation.

2
  • thanks! However, I need the latest calculated value to be displayed in the annotation view. (stored as a property of my class). It seems that I need to click on the annotation again before the correct value is displayed. Is there a way to refresh the annotation view before the callout is displayed?
    – Zhen
    May 25, 2011 at 17:14
  • @Zhen In my situation, I still make use of didSelectAnnoationView. What I then do is obtain data (in this case a thumbnail from a server) then update the callout when I have retrieved the data. Showing a simple little animation for the update. Don't know if a similar solution will help. Because there is no other way to "predict" what annotation a user is going to select.
    – MarkPowell
    May 25, 2011 at 17:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.