iosswiftmkannotationviewcalloutview

Show callout for disclosureindicator for MKAnnotationView in Swift


I am able to show a disclosure icon in on my map annotation using the following code.

  annotationView = MKAnnotationView(annotation: annotation, reuseIdentifier: annotationIdentifier)
            annotationView?.rightCalloutAccessoryView = UIButton(type: .detailDisclosure)

When you press the disclosure icon, it blinks but nothing else happens. I tried putting a button handler on it but it is not a button so the compiler said no. Do I have to create a whole gesturerecognizer to get it to do anything or how would I get a press on the the indicator to show information about the location?


Solution

  • You need this delegate method

    func mapView(_ mapView: MKMapView, 
       annotationView view: MKAnnotationView, 
       calloutAccessoryControlTapped control: UIControl)
    

    with

    self.mapView.delegate = self