Search code examples
iosswiftandroid-mapviewmkannotationview

Swift MapView -> start "didSelectAnnotation" programmatically isn't the same like to tap with a finger on annotation


My princip is easy: When you tap on an annotation (didSelectAnnotation) a infoscreen appears. When you tap on the Map the infoscreen (didDeselectAnnotation) disappears.

Now it should be possible to let the infoscreen appear, when the user tap a button, too.

So I start/call mapView(mapView: MKMapView, didSelectAnnotationView view: MKAnnotationView) in my code. This works fine. But when I click on my map, it doesn't disappear. I have first to click on the annotation (didSelectAnnoation) and after that the map listen for the didDeselectAnnoation.

What kind of problem is that and how can I fix that?

I can't find anything at google but maybe I'm searching wrong. Thank you for help and sorry for bad english (I'm still learning :) )


Solution

  • Use this method:

    func selectAnnotation(_ annotation: MKAnnotation,
                 animated animated: Bool)
    

    It selects the specified annotation and displays a callout view for it.