Search code examples
iosuitableviewmkmapviewmkannotationview

MKMapView selectAnnotation method


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?


Solution

  • int valor =0;
    
    for (MKPointAnnotation *annotation in _mapView.annotations){
    
      if ([_propLabel.text isEqual:annotation.subtitle]) {      
         [_mapView selectAnnotation:[_mapView.annotations objectAtIndex:valor] animated:true];
    
        }
    
        valor++;
    }