Most likely the map view's delegate
is not set in which case it won't call viewForAnnotation
and will instead create a default view (red pin with a callout showing only the title and subtitle -- no buttons).
The declaration in the header file does not set the map view's delegate
. That just tells the compiler that this class intends to implement certain delegate methods.
In the xib/storyboard, right-click on the map view and connect the delegate
outlet to the view controller or, in viewDidLoad
, put mapView.delegate = self;
.
Unrelated, but I want to point out that in calloutAccessoryControlTapped
, rather than checking the buttonType, you probably want to just know whether it's the right or left button so just do:
if (control == view.rightCalloutAccessoryView) ...
See https://stackoverflow.com/a/9113611/467105 for a complete example.
There are at least two problems with checking the buttonType
:
- What if you want to use the same type for both buttons (eg. Custom)?
- In iOS 7, setting a button to
UIButtonTypeDetailDisclosure
ends up actually creating a button of type Info (see MKAnnotationView always shows infoButton instead of detailDisclosure btn for details). So the check for buttonType UIButtonTypeDetailDisclosure would fail (on iOS 7).