MapKit update annotation image

女生的网名这么多〃 提交于 2019-12-04 17:17:06

I'm not sure why you're getting nil values from your markers array (especially for annotation). However, I don't recommend storing a reference to the annotation view like that.

The viewForAnnotation delegate method can get called by the map view any time it thinks it's necessary and the view object could change from one call to the next. Since you are also re-using annotation views using the same re-use identifier for each annotation, there's also the possibility that the same view object could be re-used for another annotation later.

Instead, in updateStation, I suggest the following:

  • loop through the map view's annotations array
  • if the annotation is of type EstacionEB, then check if its eid matches the one being updated
  • update the annotation's subTitle and elStatus properties (it's important to update elStatus because it's used by the viewForAnnotation delegate method to set the image)
  • get the annotation's current view by calling the map view's viewForAnnotation: instance method (this is not the same as the delegate method mapView:viewForAnnotation:)
  • update the image property of the view

See this other related question for a similar example.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!