user1904273
user1904273

Reputation: 4764

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?

Upvotes: 0

Views: 139

Answers (2)

Shehata Gamal
Shehata Gamal

Reputation: 100503

You need this delegate method

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

with

self.mapView.delegate = self

Upvotes: 1

Satish
Satish

Reputation: 2043

Try this

   let btn = UIButton(type: .detailDisclosure)
   btn.addTarget(self, action: #selector(btnDisclosureAction(_:)), for: .touchUpInside)
   annotationView.rightCalloutAccessoryView = btn

    @objc func btnDisclosureAction(_ sender: UIButton) {
        // you action
    }

Upvotes: -1

Related Questions