Search code examples
objective-cxcodemkannotationview

What CallOut have I pressed?


If I have many Annotation in my map view… how to understand what CallOut I've pressed? In tableview for example we have "didSelectRowAtIndexPath"... but here?

-(void)button:(id)sender {


[self performSegueWithIdentifier: @"dettaglio"sender: self];

}

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {

if (![[segue identifier] isEqualToString:@"dettaglio"]&&![[segue identifier]     
isEqualToString:@"cerca"])
{

[(paginaOpzioni*)segue.destinationViewController setDelegate:self];

}

if ([[segue identifier] isEqualToString:@"dettaglio"])
{
    paginaDettaglio *ibcVC = [segue destinationViewController];
    Annotazione *annotazioneDaPassare=[mapAnnotations objectAtIndex:2];
    ibcVC.immagine = annotazioneDaPassare.immagine;
    ibcVC.navigationItem.title = annotazioneDaPassare.title;
}
}

I need to change the value (2) of [mapAnnotations objectAtIndex:2]; because I want to send to the DestinationViewController the right image and text! Thanks


Solution

  • Your MKMapViewDelegate will tell you what was selected when it calls -mapView:didSelectAnnotationView:

    http://developer.apple.com/library/ios/documentation/MapKit/Reference/MKMapViewDelegate_Protocol/MKMapViewDelegate/MKMapViewDelegate.html#//apple_ref/occ/intfm/MKMapViewDelegate/mapView:didSelectAnnotationView:

    Unless of course you were referring to the accessory being tapped. That would be -mapView:annotationView:calloutAccessoryTapped:

    http://developer.apple.com/library/ios/documentation/MapKit/Reference/MKMapViewDelegate_Protocol/MKMapViewDelegate/MKMapViewDelegate.html#//apple_ref/occ/intfm/MKMapViewDelegate/mapView:annotationView:calloutAccessoryControlTapped: