首页 文章

Segue没有看到什么是错的

提问于
浏览
0

我创建了这个在 Map 上固定注释的应用程序,您可以按下按钮查看该地点的其他信息,如图片, Headers 和一些文本 . 问题是按钮完全没有任何作用,即使我实现了prepareforsegue方法 .

这是代码中存在问题的部分,如果示例代码不足,这里也是整个项目的链接Map Project

func mapView(mapView: MKMapView, viewForAnnotation annotation: MKAnnotation) -> MKAnnotationView? {
    if let annotation = annotation as? Shops{
        let identifier = "pin"
        var view: MKPinAnnotationView
        if let dequeuedView = mapView.dequeueReusableAnnotationViewWithIdentifier(identifier)
            as? MKPinAnnotationView {
                dequeuedView.annotation = annotation
                view = dequeuedView
        } else {

            view = MKPinAnnotationView(annotation: annotation, reuseIdentifier: identifier)
            view.canShowCallout = true
            view.calloutOffset = CGPoint(x: -5, y: 5)

            view.rightCalloutAccessoryView = UIButton(type: .DetailDisclosure) as UIView
        }
        return view
    }
    return nil
}

//按下按钮和segue

func Button(mapView: MKMapView, annotationView view: MKAnnotationView, calloutAccessoryControlTapped control: UIControl){
        if control == view.rightCalloutAccessoryView {

        self.performSegueWithIdentifier("ShowDetails", sender: self)
        }
    }

//转到顶部覆盖func prepareForSegue(segue:UIStoryboardSegue,sender:AnyObject?){

1 回答

  • 0

    MKMapViewDelegate函数没有该签名 .

    正确的是

    func mapView(mapView: MKMapView, annotationView view: MKAnnotationView, calloutAccessoryControlTapped control: UIControl) {
        if control == view.rightCalloutAccessoryView {
    
        self.performSegueWithIdentifier("ShowDetails", sender: self)
        }
    }
    

    您使用 Button 而不是 mapView 启动了该功能

相关问题