I made a map on my iOS Application using MapKit.
I added my pins to my view with a callout button which present de detail button inside the pin popup.
At this time, everything is good, when I tap on the detail button, I can print some text, present a new view controller but my problem is that I can't figure out how I can know which pin I've tapped.
I can solve it by using the title but it's not the best way for me, I prefer use my item id instead of a string.
If anyone knows how I can add an "id" property ton my pin or use the subtitle property (without show it on the popup bubble), I'll be grateful :)
Thank you for your help.
func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
if annotation is MKUserLocation {
return nil
}
let annotationView = MKAnnotationView(annotation: annotation, reuseIdentifier: "customAnnotation")
annotationView.image = UIImage(named: "pin")
annotationView.canShowCallout = true
annotationView.rightCalloutAccessoryView = UIButton(type: .detailDisclosure)
return annotationView
}
func mapView(_ mapView: MKMapView, annotationView view: MKAnnotationView, calloutAccessoryControlTapped control: UIControl){
print("OK, item tapped.")
}