【发布时间】:2016-10-24 14:58:59
【问题描述】:
我在这个主题上研究了将近 3 天,试图通过单击我的地图视图控制器中的地图注释的信息按钮来弄清楚如何呈现我的详细视图控制器。基本上,我可以显示注释,但是当我单击注释时,什么也没有发生。我想让它显示我的详细视图控制器,就像在我的表视图控制器中单击同一项目时,它直接进入其各自的详细视图一样。
任何帮助将不胜感激! This is the image of the map annotation I currently have
下面是我的 MapViewController 代码。我觉得我的 prepareForSegue 或 annotationView 函数有问题或缺少某些内容。
extension MapViewController {
// 1
@objc(mapView:viewForAnnotation:) func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
if let annotation = annotation as? Annotations {
let reuseID = "pin"
var view: MKPinAnnotationView
if let dequeuedView = mapView.dequeueReusableAnnotationView(withIdentifier: reuseID)
as? MKPinAnnotationView { // 2
dequeuedView.annotation = annotation
view = dequeuedView
} else {
// 3
view = MKPinAnnotationView(annotation: annotation, reuseIdentifier: reuseID)
view.canShowCallout = true
view.isUserInteractionEnabled = true
view.calloutOffset = CGPoint(x: -5, y: 5)
view.rightCalloutAccessoryView = UIButton.init(type: .detailDisclosure) as UIButton
}
return view
}
return nil
}
func mapView(mapView: MKMapView, annotationView view: MKAnnotationView!, calloutAccessoryControlTapped control: UIControl!) {
if control == view.rightCalloutAccessoryView {
print(view.annotation?.title)
performSegue(withIdentifier: "moreDetail", sender: self)
}
}
func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if (segue.identifier == "moreDetail") {
// pass data to next view
let destViewController:PancakeHouseViewController = segue.destination as! PancakeHouseViewController
destViewController.viaSegue = sender as! MKAnnotationView
}
}
}
我还在详细视图控制器 (PancakeHouseViewController) 中包含了一个变量...我不知道它是否应该存在。
var viaSegue = MKAnnotationView()
【问题讨论】:
-
绑定的 segue 是存在 segue 类型的吗?
-
正确。只是当我按下详细信息披露按钮时没有任何反应。