2010-12-30 8 views
1

Wie finde ich welche Annotation send showDetails?Wie finde ich welche Annotation send showDetails?

MKPinAnnotationView* customPinView = [[[MKPinAnnotationView alloc] 
              initWithAnnotation:annotation reuseIdentifier:BridgeAnnotationIdentifier] autorelease]; 
      customPinView.pinColor = MKPinAnnotationColorPurple; 
      customPinView.animatesDrop = YES; 
      customPinView.canShowCallout = YES; 

      // add a detail disclosure button to the callout which will open a new view controller page 
      // 
      // note: you can assign a specific call out accessory view, or as MKMapViewDelegate you can implement: 
      // - (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control; 
      // 
      UIButton* rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure]; 
      [rightButton addTarget:self 
          action:@selector(showDetails:) 
        forControlEvents:UIControlEventTouchUpInside]; 
      customPinView.rightCalloutAccessoryView = rightButton; 

      return customPinView; 

- (void)showDetails:(id)sender 
{ 
    some code 
} 

Antwort

8

Die Kommentare in Ihrem Code haben die Antwort. Anstatt eine benutzerdefinierte Methode zu verwenden und addTarget aufzurufen, verwenden Sie die delay-Methode calloutAccessoryControlTapped der Kartenansicht. Bei dieser Methode erhalten Sie einen Verweis auf die Anmerkungsansicht, die einen Verweis auf die Anmerkung enthält.

den Anruf zu addTarget entfernen und ersetzen Sie „showdetails“ Methode mit:

- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view 
    calloutAccessoryControlTapped:(UIControl *)control 
{ 
    MyAnnotationClass *annot = (MyAnnotationClass *)view.annotation; 
    //do something... 
} 
+0

aber er will unter den vielen Anmerkung wissen, was man angeklickt wurde! – carbonr

+0

@carbonr, 'view.annotation' ist derjenige, auf den geklickt wurde. Ich schlage vor, die delegate-Methode anstelle von addTarget zu verwenden. – Anna

+0

@ Carbonr, wenn Sie addTarget anstelle des Delegaten verwenden müssen oder möchten, finden Sie in dieser Antwort: http://stackoverflow.com/a/9876255/467105 – Anna

Verwandte Themen