Malloc
Malloc

Reputation: 16276

Assign a method when selecting annotation view

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.

Upvotes: 0

Views: 834

Answers (1)

NeverBe
NeverBe

Reputation: 5038

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");
}

Upvotes: 1

Related Questions