Почему мой MKAnnotationView не отображается? - Свифт - PullRequest
0 голосов
/ 09 мая 2020

Мои аннотации работают, но как только я добавляю этот код, аннотации перестают появляться. Что я делаю не так?

mapview.delegate = self

   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
    }
  let myCoordinate = CLLocationCoordinate2D(latitude: coordinate.latitude, longitude: coordinate.longitude)
             let mapAnnotation = MKPointAnnotation()
                 mapAnnotation.title = title
                 mapAnnotation.subtitle = color
                 mapAnnotation.coordinate = myCoordinate
                 self.mapView.addAnnotation(mapAnnotation)

** У меня нет настраиваемого представления аннотаций, потому что все, что я хочу сделать, это изменить цвет булавка для воздушного шара **

1 Ответ

0 голосов
/ 09 мая 2020

Вам необходимо установить делегата MapView и зарегистрировать аннотацию для mapview с тем же идентификатором.

Попробуйте

Map.register(MKAnnotationView.self, forAnnotationViewWithReuseIdentifier: "SomeRandomIdentifier")

Надеюсь, это решит проблему.

...