Search code examples
iosswift2mapkitmapkitannotation

Set first annotation in annotations


OK, I have an array of pubs:

var pubs = [Pub(coordinate: CLLocationCoordinate2D(latitude: 43.2282385, longitude: 76.855085)),
    Pub(coordinate: CLLocationCoordinate2D(latitude: 43.2345965, longitude: 76.8907758)).

and I add annotations to my map:

mapView.addAnnotations(pubs).

Then I select first annotation this way:

mapView.selectAnnotation(mapView.annotations.first!, animated: true)

But now it shows first selected annotations, then second.

Question: How to set the needed annotation first in annotations?

Thanks.


Solution

  • Howe said @ogres: mapView might re-arrange the array of the Pubs, so i had to select it from the TableView-s array mapView.selectAnnotation(tableView.annotations.first!, animated: true)