Reputation: 2829
I am facing an issue about MKMapView delegate.
In iOS5, When I clicked a Pin on the mapview,
thedidSelectAnnotationView:
delegate will be called first,
and the next is viewForAnnotation:
delegate called.
In iOS6, When I clicked a Pin on the mapview,
the viewForAnnotation:
will be called first, and the next is didSelectAnnotationView
delegate called.
So my app works fine in iOS5, but works bad in iOS6,
it's because that there are coordinate informations that I need setting in the didSelectAnnotationView:
delegate,
If viewForAnnotation:
delegate are called before the didSelectAnnotationView:
, then I'll get the wrong coordinate information.
Anybody got some idea? thank you!
Upvotes: 0
Views: 469
Reputation: 8294
viewForAnnotation
can and will be called when ever iOS needs to display one of your annotations. It is not related to when didSelectAnnotationView
is called. You may think you found a pattern in iOS 5 but that was just a fluke of something in your app and should never have been relied on. If you use it correctly it will work in iOS 5 and 6 as well as 6.1, 6.2, 6.anything and I'd guess they won't change it much to iOS 7 either. If you look in the signature of viewForAnnotation
you'll see that one of the parameters is an annotation. That is the item that your app is trying to draw and it has what ever information you gave the annotation when you called [mapView addAnnotation:myAnnotation]
. So cast it to your MKAnnotation implementation and extract the info.
Upvotes: 1
Reputation: 50089
modify the logic.
Prepare the view in viewForAnnotation (which in theory -- can be called at any time anyway). It is the right place for this!
"The annotation view to display for the specified annotation or nil if you want to display a standard annotation view."
Upvotes: 0