ios - 从 View Controller MapKit 传递数据

标签 ios swift mapkit segue

我意识到有从 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/

相关文章:

ios - 快速在 map 上添加 MKTileOverlay

iOS - 如何以编程方式计算以已知文件限制大小录制音频/视频的时间限制

ios - 我如何知道我的应用程序是由于后台刷新而启动的?

ios - 应用程序是否可以获取用户使用另一个应用程序的时间信息?

ios - SceneKit - 围绕 X 和 Z 轴旋转对象

ios - 近距离放大时折线消失

ios - 从对象外部访问 SKProductResponse

ios - 将 UILabel 放置在父级的中心

ios - 当我调用 let app = XCUIApplication() 时出现 NSInternalInconsistencyException

ios - 类的实例被释放,而键值观察者仍然在其中注册