0

I try to call a method when the annotation view (and only the annotation view) is clicked.

- (void)mapView:(MKMapView *)m didSelectAnnotationView:(MKAnnotationView *)view {

            [self openDetailView];            

}

But what i noticed, is that this method (openDetailView) is called only when i select the PIN, means before the annotation view gets displayed. How can i fire that method on callout click? Thanx in advance.

Malloc
  • 15,434
  • 34
  • 105
  • 192

1 Answers1

1

By adding button with arrow instead of callout:

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation {
    if ([annotation isMemberOfClass:[MKUserLocation class]]) {
        return nil;
    }
    MKPinAnnotationView *v =[[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"ku"] autorelease];
    UIButton *button = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
    button.frame = CGRectMake(0, 0, 24, 24);
    Shop *shop = [(ShopAnnotation *)annotation myShop];
    button.tag = [shop.ID intValue];
    [button addTarget:self action:@selector(callOutPressed:) forControlEvents:UIControlEventTouchUpInside];
    [button setImage:[UIImage imageNamed:@"map_arr_right.png"] forState:UIControlStateNormal];

    v.rightCalloutAccessoryView = button;
    v.canShowCallout = YES;
    return v;
}

- (void) callOutPressed:(id)sender {

    NSLog(@"callout pressed");
}
NeverBe
  • 5,213
  • 2
  • 25
  • 39