5

现在我想在我的 iOS 应用程序的地图上添加一个静态图钉注释。

但我只想知道是否会调用委托方法 mapView:viewForAnnotation:。

在Apple文档中,据说

 When it needs an annotation view, the map view calls the mapView:viewForAnnotation:    method of its delegate object. 

我已经阅读了一些来自 Internet 的教程和来自 Apple 的官方文档。而且我仍然不知道何时调用此方法。

4

2 回答 2

11

每当您调用 addAnnotation方法- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id < MKAnnotation >)annotation时,都会被调用。看看截图。

在此处输入图像描述

您可以在MKMapView 类参考中找到它

addAnnotationPS 在调用时设置断点,- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id < MKAnnotation >)annotation你会很容易看到函数调用的流程。

于 2012-02-25T09:40:32.503 回答
2

显然MKMapView,至少会mapView:viewForAnnotation:在需要将您显示MKAnnotationView到屏幕上时调用。

于 2012-02-25T10:39:16.527 回答