【发布时间】:2016-05-19 10:27:20
【问题描述】:
我有以下自定义注释类:
import UIKit
import MapKit
class LocationMapAnnotation: NSObject, MKAnnotation {
var title: String?
var coordinate: CLLocationCoordinate2D
var location: Location
init(title: String, coordinate: CLLocationCoordinate2D, location: Location) {
self.title = title
self.coordinate = coordinate
self.location = location
}
}
我正在将注释加载到这样的地图视图中:
for i in 0..<allLocations.count{
//Add an annotation
let l: Location = self.allLocations[i] as! Location
let coordinates = CLLocationCoordinate2DMake(l.latitude as Double, l.longitude as Double)
let annotation = LocationAnnotation(title: l.name, coordinate: coordinates, location: l)
mapView.addAnnotation(annotation)
}
我想从选定的注释中获取Location 对象。目前我有这个方法,当我点击注释时会调用它,但我不确定如何从注释中检索特定对象。
func mapView(mapView: MKMapView, didSelectAnnotationView view: MKAnnotationView) {
print("Annotation selected")
//performSegueWithIdentifier("locationInfoSegue", sender: self)
}
谢谢。
【问题讨论】:
标签: ios swift annotations mkmapview mkannotationview