0

I have a table and pressing a cell i want to see the related pin how i can do this?

I have this code:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

[_mapView selectAnnotation:[_mapView.annotations objectAtIndex:indexPath.row] animated:true];

}

The problem is that it opens another pin that is not related, what can i do?

Fabio
  • 1,913
  • 5
  • 29
  • 53
  • Then the problem might be with the `_mapView.annotations` array Or ensure with `indexPath.row OR indexPath.section` – Kumar KL Jul 01 '14 at 04:42
  • The order of the map view's `annotations` array is not guaranteed. See http://stackoverflow.com/questions/9539802/mkmapview-annotations-changing-losing-order and http://stackoverflow.com/questions/13017305/how-to-reorder-mkmapview-annotations-array. –  Jul 01 '14 at 13:58
  • You must be using some data source for your table view. In that data source, you can keep a reference to the relevant annotation object (or maybe your data source objects _are_ the annotations). –  Jul 01 '14 at 14:06
  • Thanks that is great!! I have this code to solve it – Fabio Jul 02 '14 at 02:17

1 Answers1

0
int valor =0;

for (MKPointAnnotation *annotation in _mapView.annotations){

  if ([_propLabel.text isEqual:annotation.subtitle]) {      
     [_mapView selectAnnotation:[_mapView.annotations objectAtIndex:valor] animated:true];

    }

    valor++;
}
Fabio
  • 1,913
  • 5
  • 29
  • 53