我在点击annotation view
(并且只有注释视图)时尝试调用方法。
- (void)mapView:(MKMapView *)m didSelectAnnotationView:(MKAnnotationView *)view {
[self openDetailView];
}
但是我注意到,只有当我选择openDetailView
时才会调用此方法(PIN
),这意味着在显示annotation view
之前。如何在标注点击时触发该方法?提前完成。
答案 0 :(得分: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");
}