2016-10-24 11 views
0

我對這個主題進行了近3天的研究,試圖弄清楚如何通過點擊我的地圖視圖控制器中的地圖註記的信息按鈕來呈現我的詳細視圖控制器。基本上,我可以得到註釋來顯示,但是當我單擊註釋時,什麼都不會發生。我想讓它呈現我的詳細視圖控制器,就像在我的表視圖控制器中單擊相同的項目時一樣,它直接進入其各自的詳細視圖。在swift 3中從地圖註釋中呈現詳細視圖控制器?

任何幫助將非常感激! This is the image of the map annotation I currently have

下面是我的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() 
+0

綁定的segue是否存在segue type right? – CodeChanger

+0

正確。只是當我按下詳細披露按鈕時沒有任何反應。 –

回答

0

我相信問題可能只是在方法簽名爲calloutAccessoryControlTapped。它應該是:

func mapView(_ mapView: MKMapView, annotationView view: MKAnnotationView, calloutAccessoryControlTapped control: UIControl) 
+0

通過刪除!從UIControl,詳細披露按鈕仍然不會激活並繼續到PancakeHouseViewController –

+0

您是否在'mapView'參數之前添加了'_'? – ganzogo

+0

啊哇!有效!!但它只給我提供了默認的PancakeHouseViewController ...不是連接到每個特定煎餅屋的那個。 –

相關問題