我的注释起作用了,但是一旦添加此代码,注释就会停止出现。我在做什么错?
func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
var annotationView = mapView.dequeueReusableAnnotationView(withIdentifier: "AnnotationView")
if annotationView == nil { annotationView = MKAnnotationView(annotation: annotation, reuseIdentifier: "AnnotationView") }
if annotation.subtitle == "Innovation" { annotationView?.backgroundColor = UIColor(named: "Innovation")
} else if annotation.subtitle == "Art" { annotationView?.backgroundColor = UIColor(named: "Art")
} else if annotation.subtitle == "Entertainment" { annotationView?.backgroundColor = UIColor(named: "Entertainment")
} else if annotation.subtitle == "Networking" { annotationView?.backgroundColor = UIColor(named: "Networking")
} else if annotation.subtitle == "Sale" { annotationView?.backgroundColor = UIColor(named: "Sale")
} else if annotation.subtitle == "Sports" { annotationView?.backgroundColor = UIColor(named: "Sports")
} else if annotation.subtitle == "Food & Drink" { annotationView?.backgroundColor = UIColor(named: "Food & Drink")
} else if annotation.subtitle == "Community" { annotationView?.backgroundColor = UIColor(named: "Community")
} else if annotation.subtitle == "Spiritual" { annotationView?.backgroundColor = UIColor(named: "Spiritual") }
else { annotationView?.annotation = annotation}
return annotationView
}
**我没有自定义注释视图,因为我要做的就是更改气球图钉的颜色**
您是否设置了MapView的委托?