Most likely, the map view's delegate
is not set so the viewForAnnotation
delegate method never gets called and the map view creates a default red pin with no callout accessory button.
In the storyboard, right-click on the map view control and connect its delegate
outlet to the View Controller.
Or, in code, in the viewDidLoad
method, before setting showsUserLocation
, set the delegate
programmatically:
self.mapView.delegate = self;
Some unrelated comments...
Once the button is appearing, to handle the user tapping the callout accessory, a recommended approach is to implement the calloutAccessoryControlTapped
delegate method. See the answer to MKAnnotationView Push to View Controller when DetailDesclosure Button is Clicked for an example.
A separate issue I should point out is that the gesture handler method isn't checking the gesture recognizer's state
before creating an annotation. So what can happen is multiple pins can get created while the user is still doing a single long press. To avoid this, add a check like this at the top of the longpress:
method:
if (sender.state != UIGestureRecognizerStateBegan)
{
return;
}
Another unrelated thing is that the code is creating an annotation of type myAnnotation
by doing myAnnotation alloc
but the annotation class you've shown is of type MAPpin
.
Finally, adding an MKMapView
as an IBOutlet and property in the MAPpin
class is completely unnecessary. You should remove it from there before it leads to confusion.