T. Kearsley
T. Kearsley

Reputation: 307

Pass Data from View Controller MapKit

I realise there are solutions for passing data from view controllers. However, the problem I am having is I am using Map Kit and I am unsure which Pin will be clicked on it could be one of the following:

 artworkPin = Artwork(title:"Wind Wand",locationName:"Majestic",discipline:"Statue",
                             coordinate:windwandcoord)
 artworkPin2 = Artwork(title:"Wind Wand2",locationName:" Not Majestic",discipline:"Statue",
                         coordinate:windwandcoord2)

I want the label on the ViewTwo (second view controller) to appear as the title of the pin's "info" button that was clicked on. I currently have it setup as: var artworkPin: Artwork!

override func viewDidLoad() {
    super.viewDidLoad()
    art_title.text = artworkPin.title

which only loads the label as the title of artworkPin ( the first pin ). attached code if necessary: ViewTwo ViewControllerOne

Thanks for your help.

Upvotes: 1

Views: 226

Answers (1)

Danh Huynh
Danh Huynh

Reputation: 2327

However, the problem I am having is I am using Map Kit and I am unsure which Pin will be clicked on

func mapView(_ mapView: MKMapView, annotationView view: MKAnnotationView, calloutAccessoryControlTapped control: UIControl) {
    if control == view.rightCalloutAccessoryView {
        if let artworkPin = view.annotation as? Artwork {
            performSegue(withIdentifier: "no", sender: artworkPin)
        }
    }
}

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
    if let identifier = segue.identifier {
        if identifier == "no" {
            if let artworkPin = sender as? Artwork {
                let ViewTwo = segue.destination as! ViewTwo
                ViewTwo.artworkPin = artworkPin
            }
        }
    }
}

Upvotes: 1

Related Questions