2017-05-16 48 views
1

我遇到了與我的calloutAccessoryControllerTapped問題。在我的標註中,我有兩個按鈕 - 每個按鈕都會在我的地圖視圖中繼續顯示模式彈出。在我的segue工作的那一刻,但兩個按鈕繼續到相同的彈出。我需要能夠區分按鈕和他們的segue。Mapbox - calloutAccessoryController已調整

這可能嗎?我用Google搜索這個問題,很多答案,似乎可以用下面這行代碼下面

if (control == view.leftCalloutAccessoryView) { 

但是暗示,這是來了一個錯誤「類型的值‘的UIView’沒有成員‘leftCalloutAccessoryView’。我真的很不勝感激,如果有人可以幫助我解決這個問題,很抱歉,如果我沒有解釋清楚這個問題,我已經這樣做了我最好的程度

下面是我的代碼:

func mapView(_ mapView: MGLMapView, annotationCanShowCallout annotation: MGLAnnotation) -> Bool { 

    return true 


} 


func mapView(_ mapView: MGLMapView, annotation: MGLAnnotation, calloutAccessoryControlTapped control: UIControl) { 


    self.performSegue(withIdentifier: "Show", sender: view) 

} 

func mapView(_ mapView: MGLMapView, rightCalloutAccessoryViewFor annotation: MGLAnnotation) -> UIView? { 

    guard let skateAnnotation = annotation as? SkateAnnotation else { return nil } 

    if skateAnnotation.canEdit { 
     return UIButton(type: .detailDisclosure) 
    } 

    return nil 


} 

func mapView(_ mapView: MGLMapView, leftCalloutAccessoryViewFor annotation: MGLAnnotation) -> UIView? { 

    return UIButton(type: .contactAdd) 


} 



func mapView(_ mapView: MGLMapView, imageFor annotation: MGLAnnotation) -> MGLAnnotationImage? { 

    return nil 

} 


} 

回答

0

要簡單的(變化碼根據您的需要)這可用於區分左側和右側標註附件控件。

func mapView(_ mapView: MGLMapView, leftCalloutAccessoryViewFor annotation: MGLAnnotation) -> UIView? { 
    let button = UIButton(type: .detailDisclosure) 
    button.tag = 100 
    return button 
} 

func mapView(_ mapView: MGLMapView, rightCalloutAccessoryViewFor annotation: MGLAnnotation) -> UIView? { 
    let button = UIButton(type: .detailDisclosure) 
    button.tag = 101 
    return button 
} 

func mapView(_ mapView: MGLMapView, annotation: MGLAnnotation, calloutAccessoryControlTapped control: UIControl) { 
    // Hide the callout view. 
    mapView.deselectAnnotation(annotation, animated: false) 

    if control.tag == 100 { 
     print("left") 
    } else if control.tag == 101 { 
     print("right") 
    } 
} 
+0

非常感謝!這正是我所期待的,我非常欣賞這一點! – Cal

+0

如果您不介意,請接受答案。這一切都有幫助:) – Magnas

+0

甚至沒有意識到堆棧溢出了!我是新的! – Cal