0

annotation view当(并且只有注释视图)被单击时,我尝试调用一个方法。

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

            [self openDetailView];            

}

但我注意到,openDetailView只有当我选择 , 时才会调用此方法 ( ) ,这PIN意味着在annotation view显示之前。如何在标注点击时触发该方法?提前谢谢。

4

1 回答 1

1

通过添加带箭头的按钮而不是标注:

- (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");
}
于 2012-10-16T22:24:05.943 回答