我对 swift 很陌生(来自 python),我正在努力创建 MKAnnotationView。我遵循了 ray wenderlich 的教程,但代码似乎已经过时了。该函数调用似乎不起作用,也无法产生引脚注释中应有的“i”。这是我当前使用的代码:
import MapKit
extension ViewController: MKMapViewDelegate {
// 1
func mapView(mapView: MKMapView!, viewForAnnotation annotation: MKAnnotation!) -> MKAnnotationView! {
if let annotation = annotation as? Artwork {
let identifier = "pin"
var view: MKPinAnnotationView
if let dequeuedView = MapView.dequeueReusableAnnotationView(withIdentifier: identifier)
as? MKPinAnnotationView { // 2
dequeuedView.annotation = annotation
view = dequeuedView
} else {
// 3
view = MKPinAnnotationView(annotation: annotation, reuseIdentifier: identifier)
view.canShowCallout = true
view.calloutOffset = CGPoint(x: -5, y: 5)
let button = …Run Code Online (Sandbox Code Playgroud)