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.

Cezar
  • 55,636
  • 19
  • 86
  • 87
smartsanja
  • 4,413
  • 9
  • 58
  • 106

2 Answers2

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
}
Omar Abdelhafith
  • 21,163
  • 5
  • 52
  • 56
0

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

Pass data to detailView when annotation tapped on mapview

Community
  • 1
  • 1
superGokuN
  • 1,399
  • 13
  • 28