我在MapKit中有一个自定义的标注视图,其中包含一个按钮。我想使它,以便点击这个按钮将执行一个给定的节拍。既然我是从一个.xib加载自定义标注,而它的类是UIView的一个子类(而不是UIViewController,所以我不能只在它的类文件中执行segue ),我怎么能这样做呢?
编辑
if control == view.detailCalloutAccessoryView as? CustomCalloutView {
if control.viewWithTag(6).touchesBegan {
performSegueWithIdentifier("showRentalDetailsFromCalloutView", sender: self)
}
}发布于 2016-02-19 20:21:52
实际上,有一种方法可以检测对标注的单击。这在Objective中,但是您可以将它转换为Swift,它将对您有用:
- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view
calloutAccessoryControlTapped:(UIControl *)control
{
[self performSegueWithIdentifier:@"SegueName" sender:self];
}这里引用了关于点击MKAnnotation:MKMapView MKPointAnnotation抽头事件的更详细的答案
这是我在Swift中对这种方法的解释。免责声明:我没有测试这个,但它应该指向正确的方向。
func mapView(_ mapView: MKMapView,
annotationView view: MKAnnotationView,
calloutAccessoryControlTapped control: UIControl)
{
performSegueWithIdentifier("SegueName", sender: self)
}为了完整起见,这里有一个指向MKMapViewDelegate文档的链接,其中包含有关此函数的详细信息:MKMapViewDelegate协议参考
https://stackoverflow.com/questions/35514078
复制相似问题