我已將其他堆棧帖子和教程轉換爲自定義註釋圖像,但似乎不起作用。沒有錯誤或運行時錯誤出現,只是註釋圖像不會更改。Swift - 更改註釋圖像無法正常工作
只是我在行annotationView!.image = UIImage(named: "RaceCarMan2png.png")
上設置了一個斷點,它表明該行被調用,但沒有任何反應。我將衷心感謝您的幫助。謝謝。
func mapView(mapView: MKMapView, viewForAnnotation annotation: MKAnnotation) -> MKAnnotationView? {
if annotation is MKUserLocation {
return nil
}
let identifier = "MyCustomAnnotation"
var annotationView = mapView.dequeueReusableAnnotationViewWithIdentifier(identifier)
if annotationView == nil {
annotationView = MKPinAnnotationView(annotation: annotation, reuseIdentifier: identifier)
annotationView?.canShowCallout = true
annotationView!.image = UIImage(named: "RaceCarMan2png.png")
} else {
annotationView!.annotation = annotation
}
configureDetailView(annotationView!)
return annotationView
}
func configureDetailView(annotationView: MKAnnotationView) {
annotationView.detailCalloutAccessoryView = UIImageView(image: UIImage(named: "url.jpg"))
}
非常感謝你的工作! –