按动态按钮时如何调用以下方法?
- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view
calloutAccessoryControlTapped:(UIControl *)control
答案 0 :(得分:0)
这是地图视图的委托方法,因此您的代码不会直接调用它。当点击注释视图的rightCalloutAccessoryView或leftCalloutAccessoryView时,地图视图会调用该方法。
创建地图视图时,设置其委托属性,并在viewForAnnotation方法中,创建一个按钮并将其设置为rightCalloutAccessoryView或leftCalloutAccessoryView。
例如:
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation
{
static NSString *annotationIdentifier = @"annot";
MKPinAnnotationView *pav = (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:annotationIdentifier];
if (!pav)
{
pav = [[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:annotationIdentifier] autorelease];
pav.canShowCallout = YES;
UIButton* rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
pav.rightCalloutAccessoryView = rightButton;
}
else {
pav.annotation = annotation;
}
return pav;
}
- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control
{
//handle tap on annotation...
}