为什么我的MKAnnotationView没有显示? -斯威夫特

问题描述 投票:0回答:1

我的注释起作用了,但是一旦添加此代码,注释就会停止出现。我在做什么错?

   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
    }

**我没有自定义注释视图,因为我要做的就是更改气球图钉的颜色**

swift annotations mkmapview
1个回答
0
投票

您是否设置了MapView的委托?

© www.soinside.com 2019 - 2024. All rights reserved.