我意识到有从 View Controller 传递数据的解决方案。但是,我遇到的问题是我正在使用 Map Kit,我不确定将点击哪个 Pin 图它可能是以下之一:
artworkPin = Artwork(title:"Wind Wand",locationName:"Majestic",discipline:"Statue",
coordinate:windwandcoord)
artworkPin2 = Artwork(title:"Wind Wand2",locationName:" Not Majestic",discipline:"Statue",
coordinate:windwandcoord2)
我希望 ViewTwo(第二个 View Controller )上的标签显示为被单击的图钉“信息”按钮的标题。我目前将其设置为: var artworkPin:艺术品!
override func viewDidLoad() {
super.viewDidLoad()
art_title.text = artworkPin.title
仅加载标签作为 artworkPin(第一个图钉)的标题。 如有必要,附上代码: ViewTwo ViewControllerOne
感谢您的帮助。
最佳答案
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
}
}
}
}
关于ios - 从 View Controller MapKit 传递数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40518332/