Show differents views from annotations

Hello, I have a card with different pins with a title annotation, subtitle and info button. When I click on the annotations I would like to go on a ViewController associated with the annotation clicked. In advance thank you if anyone can help me because I can not.

Are you using MapKit? If so, check out this tutorial: MapKit Tutorial: Getting Started

In the section on annotations, it shows how to launch an app when tapping on the annotation. It also references two chapters in Swift By Tutorials which would allow you to display an alert or open a detail view controller when tapping on the annotation.

Hope this helps. Have fun!

Hello, thank you for your return, yes I use mapkit, I know the course you advise me, but if I decided to ask the question out of the answers question of this course is that I did not succeed with This example to reach my different viewcontroller from my different annotations. The example opens the map kit tools and not a view controller. Therefore different pins but always with the same destination. In my case I have 10 annotations that each go to a different view. I have already done a lot of tests, the annotation is selected well but no action behind.

You could define a segue from your main map view controller to each of your 10 detail view controllers. Then in your mapView(_:annotationView:calloutAccessoryControlTapped:) method, use some identifier from your annotation to determine which segue to call with performSegueWithIdentifier:sender.

Are you using callouts? If you want to display your detail view controllers when tapping directly on the pin, use the mapView(_:didSelectAnnotationView) method and do your performSegueWithIdentifier:sender from there.

Have fun!

BONUS, that’s what I did but I must be wrong somewhere because it does not work. If you have an address or I can send you my code you may have a tip? thank you

One quick thing to check - make sure you have set the delegate of your MKMapView to your view controller. Otherwise, the map view methods won’t get called.

If that doesn’t fix it, you can post your project code here, or send it to me as a private message if you prefer. You can just control-click on your project folder and pick the “Compress xxxx” option to put all your project files into a zip file to attach to your post (or message).

Sorry for taking so long to get back with you.

Check out your definition of mapView(_:didSelectAnnotationView).

It looks like you have the closing } before the code that uses the title to execute the desired performSegue. That means the function won’t do anything at all.

Hope that helps!