0

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.

aaisataev
  • 1,643
  • 3
  • 22
  • 38
  • what do you mean by "But now it shows first selected annotations, then second." ? – ogres Nov 23 '15 at 20:10
  • I have tableView, where are 2 pubs. When I select first, it has to show first pub selected and second pub not selected. And when I select second, it has to show second pub selected and first pub not selected. (sorry for my english). But when I tap on first pub, it shows sometimes first pub, sometimes second. – aaisataev Nov 23 '15 at 20:15
  • and what happens when you do selectAnnotation ? it should do exactly as you want – ogres Nov 23 '15 at 20:16
  • When I do selectAnnotation, it selects pub randomly. – aaisataev Nov 23 '15 at 20:17
  • 1
    mapView might re-arrange the array of the Pubs, try selecting it from the TableView-s array mapView.selectAnnotation(tableView.annotations.first!, animated: true) – ogres Nov 23 '15 at 20:19
  • in what method? In prepareForSegue or didSelectRowAtIndexPath? – aaisataev Nov 23 '15 at 20:24
  • did Select Row at Index Path , if the MapView is in the different ViewController, then pass the selected Pub or selected indexPath in a different property/variable and select it after mapView is shown – ogres Nov 23 '15 at 20:25
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/95963/discussion-between-aaisataev-and-ogres). – aaisataev Nov 23 '15 at 20:30

1 Answers1

0

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)

aaisataev
  • 1,643
  • 3
  • 22
  • 38