我试图在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成为全局的?