我创建了这个在地图上修复了注释的应用程序,你可以按下按钮查看该地点的其他信息,如图片,标题和一些文字。 问题是按钮完全没有任何作用,即使我实现了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
}
//按下按钮并显示
func Button(mapView: MKMapView, annotationView view: MKAnnotationView, calloutAccessoryControlTapped control: UIControl){
if control == view.rightCalloutAccessoryView {
self.performSegueWithIdentifier("ShowDetails", sender: self)
}
}
//走到顶端 覆盖func prepareForSegue(segue:UIStoryboardSegue, 发件人:AnyObject?){
答案 0 :(得分:0)
MKMapViewDelegate函数没有该签名。
正确的是
func mapView(mapView: MKMapView, annotationView view: MKAnnotationView, calloutAccessoryControlTapped control: UIControl) {
if control == view.rightCalloutAccessoryView {
self.performSegueWithIdentifier("ShowDetails", sender: self)
}
}
您使用Button
代替mapView