3
votes

I replaced the annotations with specific pictures in map view by the method as follow:

  • (MKAnnotationView *) mapView:(MKMapView *)mapView viewForAnnotation:(id)annotation

but this method is not executed in the sequence of addAnnotation.

Which means that the "addAnnotation:" methods is executed by sequence of A,B,C,D..., but the "mapView: viewForAnnotation: " methods is executed by B,D,C,A...

How can I make the "mapView: viewForAnnotation:" methods is executed by the order of addAnnotation?

1

1 Answers

1
votes

You can't. Apple never promised to execute that function in the order you've added annotations and since viewForAnnotations is only called on annotations that are within the currently viewable area of the map it wouldn't make sense to call them in the order you're asking for. What would happen to the annotations that were off screen? What about when the user scrolls the map and more of them come into view? Loop through them all again, or just the new ones?

Instead you should add some piece of information to each annotation so you can calculate the view the map is asking for. The class you have written to implement the MKAnnotationProtocol needs to hold either the information you need to generate the right view, or a pointer to the item in your list which holds the rest of the information.