gpt4 book ai didi

ios - 在 MapKit 中用 segue 替换 pushViewController

转载 作者:可可西里 更新时间:2023-11-01 01:56:52 26 4
gpt4 key购买 nike

我用自己的 MKAnnotation 创建了应用程序。我有另一个 ViewController,我尝试通过 segue 发送数据。现在,我有了导航 Controller 和这样的工作代码

func mapView(_ mapView: MKMapView, annotationView view: MKAnnotationView, calloutAccessoryControlTapped control: UIControl) {

let annotationView:MyAnnotation = view.annotation as! MyAnnotation
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let detailStoryboard = storyboard.instantiateViewController(withIdentifier: "stationDetails") as! DetailViewController
detailStoryboard.stationTitleText = (annotationView.title)!
detailStoryboard.bikeRacksText = (annotationView.bike_racks)!
detailStoryboard.bikesText = (annotationView.bikes)!
detailStoryboard.freeRacksText = (annotationView.free_racks)!
detailStoryboard.distanceText = (annotationView.distance)!
self.navigationController?.pushViewController(detailStoryboard, animated: true)
}

但是,我想用 segue 替换 Navigation Controller。我用标识符“pinTouched”创建了 segue,并将代码中的最后一行替换为

performSegue(withIdentifier: "pinTouched", sender: nil)

我的执行函数看起来像这样

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if (segue.identifier == "pinTouched")
{
var detailScreen = segue.destination as! DetailViewController
}
}

我尝试了几种方法在此函数中发送此数据,但我只有白屏。我该如何解决?

谢谢解答! :)

最佳答案

您需要填写数据

func mapView(_ mapView: MKMapView, annotationView view: MKAnnotationView, calloutAccessoryControlTapped control: UIControl) {
performSegue(withIdentifier: "pinTouched", sender:view.annotation)
}

然后在 prepare(for segue

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if (segue.identifier == "pinTouched")
{
let detailStoryboard = segue.destination as! DetailViewController
let annotationView = sender as! MyAnnotation
detailStoryboard.stationTitleText = (annotationView.title)!
detailStoryboard.bikeRacksText = (annotationView.bike_racks)!
detailStoryboard.bikesText = (annotationView.bikes)!
detailStoryboard.freeRacksText = (annotationView.free_racks)!
detailStoryboard.distanceText = (annotationView.distance)!
}
}

关于ios - 在 MapKit 中用 segue 替换 pushViewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52080093/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com