0

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?

user1904273
  • 4,562
  • 11
  • 45
  • 96

2 Answers2

1

You need this delegate method

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

with

self.mapView.delegate = self
Shehata Gamal
  • 98,760
  • 8
  • 65
  • 87
  • One question if you come back to this. Is there a recommended way to create a view when the disclosure control is tapped to show additional information such as a small callout view to the calloutview or an expanded calloutview? All I want to do is show a address and phone number. Are we supposed to make a new view ourselves and display it or is there something built in? – user1904273 Nov 15 '18 at 19:57
-1

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
    }
Satish
  • 2,015
  • 1
  • 14
  • 22
  • Hey, can anyone let me know what's wrong with this code, just want to understand how people downvote answers – Satish Nov 14 '18 at 20:57