-1

I customized my callOutView, creating an own AnnotationView theGreatAnnotationView, but I want to keep the standard Annotation Pin on the map. In this code I use a custom annotation image view?.image = annotation.image but when is delete the line, there is no annotation on my map. Can you help me solving this problem?

func mapView(_ surroundingMapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {

    var annoView: MKAnnotationView?
    if annotation.isKind(of: MKUserLocation.self) {  

        return nil 
    }



    var view = surroundingMapView.dequeueReusableAnnotationView(withIdentifier: "imageAnnotation")
    if view == nil {
        view = theGreatAnnotationView(annotation: annotation, reuseIdentifier: "imageAnnotation")
        reuseIdentifier: "imageAnnotation")
        view!.canShowCallout = false

    }

    let annotation = annotation as! Artwork


    view?.image = annotation.image
    view?.annotation = annotation


    return view
}
Nissa
  • 4,636
  • 8
  • 29
  • 37
TheRJI
  • 17
  • 2
  • If you want a standard pin on your map rather than an `image`, you should use `MKPinAnnotationView`. – Rob Oct 14 '17 at 20:45

1 Answers1

0

You should use MKPinAnnotationView instead of MKAnnotationView.

func mapView(_ surroundingMapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {

    var annoView: MKAnnotationView?
    if annotation.isKind(of: MKUserLocation.self) {

        return nil
    }

    if /* if annotation is image */ {
        var view = surroundingMapView.dequeueReusableAnnotationView(withIdentifier: "imageAnnotation")
        if view == nil {
            view = theGreatAnnotationView(annotation: annotation, reuseIdentifier: "imageAnnotation")
            view!.canShowCallout = false

        }

        let annotation = annotation as! Artwork


        view?.image = annotation.image
        view?.annotation = annotation
    } else {
        /* if annotation is pin */
        var view = surroundingMapView.dequeueReusableAnnotationView(withIdentifier: "pinAnnotation")
        if view == nil {
            view = MKPinAnnotationView(annotation: annotation, reuseIdentifier: "pinAnnotation")
            view!.canShowCallout = false
        }

        let annotation = annotation as! Artwork


        view?.annotation = annotation
    }

    return view
}
Kosuke Ogawa
  • 7,383
  • 3
  • 31
  • 52
  • Thank you for your answer. I want to use my theGreatAnnotationView for every annotation (because of the callOutView of the annotations), but still want the standart Annotation Pin image for every annotation. So there are no two cases. – TheRJI Oct 18 '17 at 16:59