私はマップビューコントローラのマップ注釈の情報ボタンをクリックして、詳細ビューコントローラを表示する方法を理解しようと、ほぼ3日間このトピックを調べました。基本的に注釈を表示することはできますが、注釈をクリックすると何も起こりません。詳細ビューコントローラを表示させたいのですが、テーブルビューコントローラで同じアイテムをクリックすると、それぞれの詳細ビューに直接移動するのと同じ方法です。スワイプ3のマップ注釈からディテールビューコントローラを表示しますか?
どんな助力でも大歓迎です!
以下は私のMapViewControllerのコードです。私は、何か間違っているか、私のprepareForSegueまたはannotationViewのいずれかの機能に欠けているような気がします。そこかないことになっている場合
extension MapViewController {
// 1
@objc(mapView:viewForAnnotation:) func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
if let annotation = annotation as? Annotations {
let reuseID = "pin"
var view: MKPinAnnotationView
if let dequeuedView = mapView.dequeueReusableAnnotationView(withIdentifier: reuseID)
as? MKPinAnnotationView { // 2
dequeuedView.annotation = annotation
view = dequeuedView
} else {
// 3
view = MKPinAnnotationView(annotation: annotation, reuseIdentifier: reuseID)
view.canShowCallout = true
view.isUserInteractionEnabled = true
view.calloutOffset = CGPoint(x: -5, y: 5)
view.rightCalloutAccessoryView = UIButton.init(type: .detailDisclosure) as UIButton
}
return view
}
return nil
}
func mapView(mapView: MKMapView, annotationView view: MKAnnotationView!, calloutAccessoryControlTapped control: UIControl!) {
if control == view.rightCalloutAccessoryView {
print(view.annotation?.title)
performSegue(withIdentifier: "moreDetail", sender: self)
}
}
func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if (segue.identifier == "moreDetail") {
// pass data to next view
let destViewController:PancakeHouseViewController = segue.destination as! PancakeHouseViewController
destViewController.viaSegue = sender as! MKAnnotationView
}
}
}
は、私も私のディテール・ビュー・コントローラ(PancakeHouseViewController)内部変数が含まれていた...私は知りません。
var viaSegue = MKAnnotationView()
セグがありますか? – CodeChanger
が正しい。詳細開示ボタンを押すと何も起こりません。 –