我試圖在RightCalloutAccessoryView的DetailDisclosure按鈕被點擊時,將ViewController1(VC1)中所選MKAnnotation的座標,標題和副標題傳遞給ViewController2(VC2)。我有一個從VC1到VC2的標識符viaSegue。我在VC2中有一個帶標識符viaSegueLabel的標籤,我想將座標顯示爲字符串。將選定註釋的座標傳遞給新視圖控制器Swift 2.0
是定製MKAnnotation的召喚出來,以便它顯示在rightCalloutAccessoryView一個DetailDisclosure按鈕看起來功能,如:
// Customize Annotation Callout
func mapView(mapView: MKMapView, viewForAnnotation annotation: MKAnnotation) -> MKAnnotationView? {
// 1
let identifier = "Capital"
// 2
if annotation.isKindOfClass(Capital.self) {
// 3
var annotationView = mapView.dequeueReusableAnnotationViewWithIdentifier(identifier)
if annotationView == nil {
//4
annotationView = MKPinAnnotationView(annotation:annotation, reuseIdentifier:identifier)
annotationView!.canShowCallout = true
// 5
let btn = UIButton(type: .DetailDisclosure)
annotationView!.rightCalloutAccessoryView = btn
} else {
// 6
annotationView!.annotation = annotation
}
return annotationView
}
// 7
return nil
}
這需要用戶從VC1到VC2當DetailDisclosure按鈕被點擊貌似功能:
// When righCalloutAccessoryView is tapped, segue to newView
func mapView(mapView: MKMapView, annotationView view: MKAnnotationView, calloutAccessoryControlTapped control: UIControl) {
self.performSegueWithIdentifier("newView", sender: view)
}
而且我覺得我需要實現來完成這個看起來像函數:
// Pass data to newView
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject!) {
if (segue.identifier == "newView") {
let destViewController:BusStopSettingsViewController = segue.destinationViewController as! BusStopSettingsViewController
destViewController.viaSegue = // not sure how to reference selected Annotation here
}
}
在prepareForSegue()的最後一行中,我需要引用當前選定的MKAnnotation。是否有內置Swift的方法可以讓我這樣做,還是應該使Annotation成爲全局的?