我试着让呼叫器发挥作用,但这并没有发生,因为我在准备比赛时做错了什么。我想知道如何才能对另一个视图做一个引脚注释?
发布于 2015-11-29 02:32:43
当点击标注中的按钮时,切换到另一个场景的过程是这样的:
delegate设置为视图控制器。您可以在Interface的“连接检查器”中这样做,也可以通过编程的方式。您希望指定视图控制器也符合MKMapViewDelegate。MKMapView使用此注释视图。iOS 11简化了这个过程,但我将介绍如何做到这两种方法:- If your minimum iOS version is 11 (or later), you’d just register the custom annotation view in as the default and you’re done. You generally don't implement `mapView(_:viewFor:)` at all in iOS 11 and later. (The only time you might implement that method is if you needed to register multiple reuse identifiers because you had multiple types of custom annotation types.)重写func viewDidLoad() { super.viewDidLoad() mapView.register(CustomAnnotationView.self,forAnnotationViewWithReuseIdentifier: forAnnotationViewWithReuseIdentifier})
-如果您需要在11之前支持iOS版本,您将确保将视图控制器指定为MKMapView的委托,然后实现mapView(_:viewFor:):
扩展ViewController: MKMapViewDelegate { func mapView(_ mapView: MKMapView,viewFor注释: MKAnnotation) -> MKAnnotationView?{ if注释是MKUserLocation {返回nil } let reuseIdentifier =“.”变量annotationView = reuseIdentifier)如果annotationView == nil { annotationView =CustomAnnotationView(注释:注释,reuseIdentifier: reuseIdentifier) } annotationView { annotationView?.annotation =注释}返回annotationView}
例如,这会产生一个类似于以下内容的标注,右边是.infoLight按钮:

calloutAccessoryControlTapped:
func mapView(_ mapView: MKMapView,annotationView视图: MKAnnotationView,calloutAccessoryControlTapped控件: UIControl) { performSegue(withIdentifier:"SegueToSecondViewController",发送方:视图)}
显然,这假设您已经在两个视图控制器之间定义了一个segue。有关更多信息,请参见“位置和地图编程指南”中的创建标注。
有关上述Swift 2的实现,请参见先前对这一答案的修订。
https://stackoverflow.com/questions/33978455
复制相似问题