Ich habe mit benutzerdefinierten Kartenhinweisen gearbeitet und habe sie zur Arbeit gebracht. Schade, das sind nicht diese Situationen, weil ich versucht habe, herauszufinden, warum ich diesen Fehler immer wieder bekomme: "Es konnte kein Wert des Typs 'NSKVONotifying_MKPointAnnotation' (0x1c0115960) in 'ShopPeer.CustomBusinessPoint' (0x101159c68) umgewandelt werden." Ich bekomme diesen Fehler online "lass customAnnotation = view.annotation as! CustomBusinessPoint". Ich benutze dieses Tutorial als Beispiel: http://sweettutos.com/2016/03/16/how-to-completely-customise-your-map-annotations-callout-views/ ... Schau auch im Compiler im Bild unten, um zu sehen, wie viele Ansichten erscheinen ... nicht sicher, warum es so viele gibt.Swift Custom Map Call Out Fehler
func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
guard !(annotation is MKUserLocation) else { return nil }
let reuseId = "pin"
if let pinView = mapView.dequeueReusableAnnotationView(withIdentifier: reuseId) as? CustomBusinessCallOutAnnotatiion {
return pinView
} else {
let pinView = MKPinAnnotationView(annotation: annotation, reuseIdentifier: reuseId)
pinView.pinTintColor = UIColor.red
pinView.canShowCallout = false
//pinView.rightCalloutAccessoryView = UIButton(type: UIButtonType.infoLight)
return pinView
}
}
func mapView(_ mapView: MKMapView, didSelect view: MKAnnotationView) {
if view.annotation is MKUserLocation { return }
let customAnnotation = view.annotation as! CustomBusinessPoint
let views = Bundle.main.loadNibNamed("CustomBusinessCallOut", owner: nil, options: nil)
let calloutView = views?[0] as! CustomBusinessCallOut
calloutView.businessName.text = customAnnotation.businessName
calloutView.center = CGPoint(x: view.bounds.size.width/2, y: -calloutView.bounds.size.height * -0.0001)
view.addSubview(calloutView)
mapView.setCenter((view.annotation?.coordinate)!, animated: true)
}