目前我从API中提取JSON并将其发布到MapKit Map。它从API中提取并将其解析为Class Market数组,并且每个邮政编码的大小都不同。目前,我正在尝试获取单击的特定注释标注的信息,并在信息按钮单击上将其发送到新的视图控制器。
这是我准备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
}
答案 0 :(得分:0)
应该只是:
destination.market = sender as? Market
或者我错过了什么?