0
MapKitの注釈に吹き出しを追加しようとしていますが、オンラインでかなり検索した後では機能しません。注釈コールアウトが機能しないSwift
これは、現時点で正常に動作する各アノテーションを現在作成しているところです。
struct loc {
let title: String
let latitude: Double
let longitude: Double
let phone: Int
//let subTitle: String
}
var locs = [
loc(title: "New York, NY", latitude: 40.713054, longitude: -74.007228, phone: 2334), //subTitle: "Sub title"),
]
func placeAnnotations() {
let annotations = locs.map { location -> MKAnnotation in
let annotation = MKPointAnnotation()
annotation.title = location.title
annotation.coordinate = CLLocationCoordinate2D(latitude: location.latitude, longitude: location.longitude)
//annotation.subtitle = location.subTitle
return annotation
}
mapView.addAnnotations(annotations)
}
(Iは、配列LOCSにデータを追加する機能を持っている)
そして、これは動作していない吹き出しを追加しようとすると、私が持っているものです。
あなたが使用func mapView(mapView: MKMapView, viewForAnnotation annotation: MKAnnotation) -> MKAnnotationView? {
if annotation is MKUserLocation { return nil }
let identifier = "pin"
var annotationView = mapView.dequeueReusableAnnotationView(withIdentifier: identifier) as? MKPinAnnotationView
if annotationView == nil {
annotationView = MKPinAnnotationView(annotation: annotation, reuseIdentifier: identifier)
annotationView?.canShowCallout = true
annotationView?.rightCalloutAccessoryView = UIButton(type: .infoDark)
} else {
annotationView?.annotation = annotation
}
return annotationView
}
です。 'mapView.delegate'を' mapView..'関数で 'UIViewController'に設定しましたか? – JuicyFruit
いいえ、私は持っていないと思っています。私はそれをやろうとしましたが、クラッシュしました。これを正しく行うにはどうすればいいですか? –
あなたは 'mapView.delegate = self'を行うべきです、どうしてクラッシュしますか? – JuicyFruit