The viewForAnnotation
delegate method will be called by the map view automatically (you don't explicitly "run" it).
The most likely reason the map view is not calling it is that the map view's delegate
is not set.
In the storyboard or xib, make sure the map view's delegate
outlet is connected to the view controller (right-click or ctrl-click the map view and connect the delegate outlet to the view controller).
Or, you can add this line in the code in viewDidLoad
before the setMapType
:
//code of map
mapMKMapView.delegate = self; // <-- add this line
[mapMKMapView setMapType:MKMapTypeStandard];
An unrelated point:
Instead of using a custom action method for the button, I suggest using the map view's own calloutAccessoryControlTapped
delegate method. In that method, you'll get direct access to the annotation object that was tapped (via view.annotation
). Remove the addTarget
and the button:
method if you decide to use the delegate method.