views:

247

answers:

2

I'm displaying some icons (annotations) on a map in my app by loading them into an NSMutableArray and then adding the array. It works nicely, but I'm having trouble displaying them in proper layer order.

Sometimes, icons that I've added to positionIcons last appear on top; other times, the most recent are shown below the older ones.

How can I ensure layer order?

[positionIcons removeAllObjects];
[positionIcons insertObject:<someObject> atIndex:0];
[mapView addAnnotations:positionIcons];
+1  A: 

You will probably have to implement -mapView:didAddAnnotationViews: on your MKMapViewDelegate and then fiddle with their ordering via their superview, possibly with methods like -bringSubviewToFront:.

John Calsbeek
I'm pretty ignorant in objective c. Is the delegate where I'm declaring the map view? If using bringSubviewToFront, how do I discern one icon from another (what data is carried at that point)? Is there any way to set order as I put icons in?
BankStrong
The delegate is the object that you stick in the `delegate` property of the `MKMapView`. Everything in the passed array will be an `MKAnnotationView` whose `annotation` property is the annotation you originally put in the `positionIcons` array.
John Calsbeek
A: 

May be this is what you seek (How to define the order of overlapping MKAnnotationViews)

tt.Kilew