我有注释的地图,点击PIN后,标注显示了注释的标题和披露按钮。当我点击按钮SEGUE被触发,我移动到另一个视图。如何确定单击什么注释,或标题传递到另一个视图。
func mapView(mapView: MKMapView!,
viewForAnnotation annotation: MKAnnotation!) -> MKAnnotationView! {
if annotation is MKUserLocation{
return nil
}
let reuseId = "pin"
var pinView = mapView.dequeueReusableAnnotationViewWithIdentifier(reuseId) as? MKPinAnnotationView
if(pinView == nil){
pinView = MKPinAnnotationView(annotation: annotation, reuseIdentifier: reuseId)
pinView!.canShowCallout = true
pinView!.animatesDrop = true
pinView!.pinColor = .Red
var calloutButton = UIButton.buttonWithType(.DetailDisclosure) as UIButton
pinView!.rightCalloutAccessoryView = calloutButton
} else {
pinView!.annotation = annotation
}
return pinView!
}
func mapView(mapView: MKMapView!, annotationView: MKAnnotationView, calloutAccessoryControlTapped control: UIControl) {
if control == annotationView.rightCalloutAccessoryView {
performSegueWithIdentifier("Detail", sender: self)
}
}
谢谢
您可以使用MKAnnotation
title
财产annotation
寻找引脚如果注释标题是不同的
annotationView.annotation.title
返回String
.Compare String
者区分。
要么
使用在tag
pinview
财产
pinView!.tag //set tag for each pin in `viewForAnnotation` method
在
func mapView(mapView: MKMapView!, annotationView: MKAnnotationView, calloutAccessoryControlTapped control: UIControl) {
//get tag here
if(annotationView.tag == 0){
//Do for 0 pin
}
if control == annotationView.rightCalloutAccessoryView {
performSegueWithIdentifier("Detail", sender: self)
}
}
请尝试保存标题给你然后NSUserDefaults的抓住该对象在新的视图。这是我使用的方法。
func mapView(mapView: MKMapView!, annotationView view: MKAnnotationView!, calloutAccessoryControlTapped control: UIControl!) {
if control == view.rightCalloutAccessoryView{
println(view.annotation.title) // annotation's title
let title = view.annotation.title
NSUserDefaults.standardUserDefaults().setObject(title, forKey: "Title")
var InfoView = self.storyboard?.instantiateViewControllerWithIdentifier("Spot") as! UIViewController
一旦保存标题到你NSUserDefaults的可以简单地抢在新“的InfoView或任何你在呼唤它”像这样let spotTitle = NSUserDefaults.standardUserDefaults().objectForKey("SpotTitle") as! String
对象
希望这可以帮助