0

I am creating an annotation callout with right accessory button, using the following code

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation
{

if ([annotation isKindOfClass:[MKUserLocation class]]){
    return nil;
}

else {

    static NSString *AnnotationViewID = @"annotationViewID";

    MKAnnotationView *annotationView = (MKAnnotationView *)[self.mapView dequeueReusableAnnotationViewWithIdentifier:AnnotationViewID];

    if (annotationView == nil)
    {
        annotationView = [[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:AnnotationViewID];
    }

    annotationView.image = [UIImage imageNamed:@"Mevents.png"];
    annotationView.annotation = annotation;
    annotationView.canShowCallout=YES;

    UIButton* rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
    [rightButton setTitle:annotation.title forState:UIControlStateNormal];
    [rightButton addTarget:self action:@selector(showDetails:) forControlEvents:UIControlEventTouchUpInside];

    annotationView.rightCalloutAccessoryView = rightButton;

    //  UIImageView *profileIconView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"profile.png"]];
    //  pinView.leftCalloutAccessoryView = profileIconView;
    //  [profileIconView release];

    return annotationView;

}

}

How can I track, which annotation is clicked? I want to load the details screen with the id and fetch the data based on that id to show info.

4

2 回答 2

0

When you create the annotation add a tag to it

annotationView.image = [UIImage imageNamed:@"Mevents.png"];
//Add this after
annotationView.tag = 111;

Now in viewForAnnotation, check for this tag

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation
{

if ([annotation isKindOfClass:[MKUserLocation class]]){
    return nil;

    if(annotation.tag == 111)
        //Do something
    else
        //Do some other thing
}
于 2012-06-18T09:42:48.323 回答
0

hey bro check my answer in the following thread it can help you.

Pass data to detailView when annotation tapped on mapview

于 2012-06-18T10:03:35.500 回答