Pergunta

Actually I'm developing something in my app which displays annotations within my MKMapView and those annotations should be clickable and pass a param to a method.
The problem is for now how to pass the parameter to the next function when tapping the disclosure button.
For the formatting of the annotations I use the - (MKAnnotationView *)mapView:(MKMapView *)aMapView viewForAnnotation:(id <MKAnnotation>)annotation method to display the disclosure button. But the problem is, how to get values out of the Annotation object which is displayed at the moment?

My code for the Annotation (only the relevant part):

@synthesize coordinate, id, title, subtitle;

+ (id)annotationWithCoordinate:(CLLocationCoordinate2D)coordinate {
    return [[[[self class] alloc] initWithCoordinate:coordinate] autorelease];
}

- (id)initWithCoordinate:(CLLocationCoordinate2D)coordinate {
    self = [super init];

    if(nil != self) {
        self.coordinate = coordinate;
    }

    return self;
}

And when touching the disclosure button the method - (void)displayInfo:(NSNumber *) anId; should be called with handing over Annotation.id as the anId param.

The disclosure button is generated with that code:

   UIButton *disclosureButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];

    dropPin.rightCalloutAccessoryView = disclosureButton;
    dropPin.animatesDrop = YES;
    dropPin.canShowCallout = YES;

So - the question:
How can I pass that param to the function OR read the id of the clicked Annotation?

I thought I could do the handling of the tap on disclosureButton either with a selector for UIButton (but - how to pass the id?) or with - (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control (again - how to pass the id?).

I hope you know what I mean and very big thanks in advance for your answers! :)

Foi útil?

Solução

In calloutAccessoryControlTapped the annotation is available via the view:

MKAnnotation *annotation = view.annotation;
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top