I have to tap an MKannotationView TWICE to be redirected…
is there a way to click MKannotationView only once and be redirected?
current behavior:
-tap into a MKannotationView
-shows bubble with annotation view details
-click bubble and I’m redirected to view with details
I’d like this behavior:
-tap into a MKannotationView
-I’m redirected to view with details
func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
if annotation is MKUserLocation {
return nil
}
var annotationView = mapView.dequeueReusableAnnotationView(withIdentifier: "listings")
if annotationView == nil {
annotationView = MKAnnotationView(annotation: annotation, reuseIdentifier: "listings")
let lbl = UILabel(frame: CGRect(x: 0, y: 0, width: 50, height: 30))
lbl.backgroundColor = .blue
lbl.textColor = .white
lbl.tag = 42
annotationView!.addSubview(lbl)
annotationView!.canShowCallout = true
annotationView!.rightCalloutAccessoryView = UIButton(type: .detailDisclosure)
annotationView!.frame = lbl.frame
} else {
annotationView!.annotation = annotation
}
let lbl = annotationView!.viewWithTag(42) as! UILabel
lbl.text = annotation.subtitle!
return annotationView
}
func mapView(_ mapView: MKMapView, annotationView view: MKAnnotationView, calloutAccessoryControlTapped control: UIControl) {
for listingHere in map.model.results!.listings {
if listingHere.address == view.annotation?.title {
map.selectedListing = listingHere
return
}
}
}