Jean
Jean

Reputation: 5

Add action to an AnnotationPin in swift

I've made a "classic" map on swift, with the user location and some AnnotationPin. I use the default look for iOS 11 so when I click on a Pin, it gets bigger. The name and subname are also displayed below the pins.

My question is : How do I add an action so that if I click on a Pin, I go to another page to display stuffs ? Maybe I could replace this "zoom" on the pin or add my action there, but I don't know how (I'm a beginner).

Thanks ! :)

Upvotes: 0

Views: 373

Answers (1)

Kosuke Ogawa
Kosuke Ogawa

Reputation: 7451

Use mapView's didSelect delegate method.

func mapView(_ mapView: MKMapView, didSelect view: MKAnnotationView) {
    performSegue(withIdentifier: "toTheMoon", sender: self)
}

See also How to perform segue programmatically in Xcode 8 : Swift 3

Upvotes: 1

Related Questions