2017-05-16 96 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