Ios Swift-按下MKAnnotation按钮时如何触发序列?
快速新手问题: 我有两个视图控制器:我的家用VC,它使用MapKit和第二个“MapDetailViewController”来显示附加信息 在home VC上,我添加了一个带有注释的兴趣点,当用户单击pin时,可以显示该点的名称和字幕。当用户单击地图批注时,如何切换到我的MapDetailViewControllerIos Swift-按下MKAnnotation按钮时如何触发序列?,ios,swift,mapkit,segue,mkannotation,Ios,Swift,Mapkit,Segue,Mkannotation,快速新手问题: 我有两个视图控制器:我的家用VC,它使用MapKit和第二个“MapDetailViewController”来显示附加信息 在home VC上,我添加了一个带有注释的兴趣点,当用户单击pin时,可以显示该点的名称和字幕。当用户单击地图批注时,如何切换到我的MapDetailViewController // Map view delegate which handles the annotation view extension ViewController: MKMa
// Map view delegate which handles the annotation view
extension ViewController: MKMapViewDelegate {
func mapView(_ mapView: MKMapView, viewFor annotation:
MKAnnotation) ->
MKAnnotationView? {
guard let annotation = annotation as? Artwork else { return nil }
let identifier = "marker"
var view: MKMarkerAnnotationView
if let dequeuedView =
mapView.dequeueReusableAnnotationView(withIdentifier: identifier) as?
MKMarkerAnnotationView {
dequeuedView.annotation = annotation
view = dequeuedView
} else {
view = MKMarkerAnnotationView(annotation: annotation,
reuseIdentifier: identifier)
view.canShowCallout = true
view.calloutOffset = CGPoint(x: -5, y: 5)
// Broke up the button initialisation so that it has unique id 'button'
let button = UIButton(type: .detailDisclosure)
view.rightCalloutAccessoryView = button
// Make the segue happen - tried to make it happen when object 'button' is pressed
performSegue(withIdentifier: "MapDetail", sender: button)
}
return view
}
这是我在做的一个老项目的摘录。当点击注释上的信息附件时,它会打开一个新的tableview控制器。我创建了一个名为Annotation的自定义类,它保存了有关注释的所有信息。我不确定这是否有帮助:)
func mapView(_ mapView: MKMapView, annotationView view: MKAnnotationView,
calloutAccessoryControlTapped control: UIControl) {
let annotation = view.annotation as! Annotation
let event = annotation.event
if control == view.rightCalloutAccessoryView {
let destination = self.storyboard!.instantiateViewController(withIdentifier: "EventViewController") as! EventViewController
self.navigationController!.pushViewController(destination, animated: true)
destination.event = event
}
}