gpt4 book ai didi

ios - 如何将来自 MapKit 注释的信息发送到新的 View Controller

转载 作者:行者123 更新时间:2023-11-28 07:55:17 26 4
gpt4 key购买 nike

目前我正在从 API 中提取 JSON 并将其发布到 MapKit map 。它从 API 中提取并将其解析为类市场数组,每个邮政编码的大小都不同。目前,我正在尝试获取我单击的特定注释标注的信息,并在单击信息按钮时将其发送到新的 View Controller 。

这是我准备 segue 的代码,当按下信息按钮时:

    //This method gets ran when the information button is pressed on the Annotation's Callout

func mapView(_ mapView: MKMapView, annotationView view: MKAnnotationView,
calloutAccessoryControlTapped control: UIControl) {
let market = view.annotation as! Market

performSegue(withIdentifier: "callout", sender: market)

}

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
let destination = segue.destination as! CalloutViewController

destination.market = //Yes this line isn't completed, Not sure how to get the current class from the annotation's callout when it is pressed!

let backItem = UIBarButtonItem()
backItem.title = "Back"
navigationItem.backBarButtonItem = backItem
}

这是 Callout View Controller(我正在尝试获取信息以继续使用的那个。):

class CalloutViewController: UIViewController {

let market: Market! = nil

@IBOutlet weak var testView: UITextView!

override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.

self.navigationController?.navigationBar.tintColor = UIColor.white
}

最佳答案

应该是:

destination.market = sender as? Market

还是我遗漏了什么?

关于ios - 如何将来自 MapKit 注释的信息发送到新的 View Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48360416/

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