我的地图上有 1 个图钉。我需要将注释标题传递给另一个 UIView(在这种情况下是 ikinci Ekran.swift)。但我无法这样做。
这是我的代码的segue部分,我不知道如何segue所选注释的标题。
我只粘贴了相关部分的代码。
class MapViewController: UIViewController, CLLocationManagerDelegate, MKMapViewDelegate {
@IBOutlet weak var mapView: MKMapView!
@IBOutlet weak var lbl_Name: UILabel!
@IBOutlet weak var lbl_Address: UILabel!
@IBOutlet weak var lbl_Phone: UILabel!
var LocationManager = CLLocationManager()
var i = 0
var annotation:MKAnnotation!
override func viewDidLoad() {
super.viewDidLoad()
LocationManager.delegate = self
mapView.delegate = self
LocationManager.desiredAccuracy = kCLLocationAccuracyNearestTenMeters
LocationManager.requestWhenInUseAuthorization()
LocationManager.startUpdatingLocation()
let tekel1 = TekelClass(
title: "tekel1",
locationName: "Tekelİsim1",
coordinate: CLLocationCoordinate2D(latitude: 40.9400, longitude: 29.300520))
mapView.addAnnotation(tekel1)
}
func mapView(mapView: MKMapView!, annotationView view: MKAnnotationView!,
calloutAccessoryControlTapped control: UIControl!) {
if control == view.rightCalloutAccessoryView {
performSegueWithIdentifier("toTheMoon", sender: self)
}
}
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if (segue.identifier == "toTheMoon" )
{
var ikinciEkran = segue.destinationViewController as! DetailViewController
ikinciEkran.tekelName = "how to segue title of the selected pin"
}
}
你需要实施viewForAnnotation
method.
example.
func mapView(mapView: MKMapView!, viewForAnnotation annotation: MKAnnotation!) -> MKAnnotationView! {
if annotation is MKUserLocation {
return nil
}
let reuseId = "pin"
var pinView = mapView.dequeueReusableAnnotationViewWithIdentifier(reuseId)
if pinView == nil {
pinView = MKPinAnnotationView(annotation: annotation, reuseIdentifier: reuseId)
pinView?.canShowCallout = true
var rightButton: AnyObject! = UIButton.buttonWithType(UIButtonType.DetailDisclosure)
rightButton.titleForState(UIControlState.Normal)
pinView!.rightCalloutAccessoryView = rightButton as! UIView
}
else {
pinView?.annotation = annotation
}
return pinView
}
如果用户点击注释上的 (i) 按钮,calloutAccessoryControlTapped
将被调用。
参考号我的 MKMapView 示例代码https://github.com/kookawa/MKMapViewSample https://github.com/koogawa/MKMapViewSample
EDIT
func mapView(mapView: MKMapView, annotationView view: MKAnnotationView, calloutAccessoryControlTapped control: UIControl) {
if control == view.rightCalloutAccessoryView {
performSegueWithIdentifier("toTheMoon", sender: view)
}
}
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if (segue.identifier == "toTheMoon" )
{
var ikinciEkran = segue.destinationViewController as! DetailViewController
ikinciEkran.tekelName = (sender as! MKAnnotationView).annotation!.title
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)