2015-11-18 31 views
0

我在我的地图上有注释。我想在用户点击AccessoryControl并将数据传递给视图控制器时打开一个新的视图控制器。将数据传递给MapDetailViewController

所以我这样做:

func mapView(mapView: MKMapView, annotationView view: MKAnnotationView, calloutAccessoryControlTapped control: UIControl) { 
    self.performSegueWithIdentifier("Details", sender: view) 
} 

则:

if segue.identifier == "Details" { 

     let placeDetailViewController = segue.destinationViewController as! PlaceDetailViewController 

     let place: Place = places[?index?] 
     placeDetailViewController.place = place 
} 

所以我想我的注释的指标,不知道如何做到这一点。

帮助。谢谢。

回答

1

你需要做的是在prepareForSegue

override func prepareForSegue(segue: UIStoryboardSegue?, sender: AnyObject?) { 
     if segue!.identifier == "Details" { 
      let vc = segue!.destinationViewController as PlaceDetailViewController 
      vc.data = "YOUR_DATA_HERE" 
     } 
    } 
+0

不是字符串,但整个物体 – aaisataev

+0

你可以注解为您的**发件人属性**(_view_您的例子)和将其设置为** vc.annotation = sender.annotation **。或者创建任何其他财产 –