2017-05-16 13 views
1

내 calloutAccessoryControllerTapped에 문제가 있습니다. 분당 내 설명 표 내에 두 개의 버튼이 있습니다. 각 버튼은 내지도보기에서 모달 팝업으로 이어집니다. 잠시 후 내 segue는 작동하지만 두 버튼 모두 같은 팝업으로 이어집니다. 나는 버튼과 그들의 구별을 구별 할 수 있어야한다.지도 - calloutAccessoryControllerTapped

이것이 가능합니까? 나는이 질문을 검색 좀 많은 답변이 유형의이 오류와 함께오고있다 "값 그러나

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