开发者

how to call this method when pressing the button

How to call this below method when pressing the dynamic button?

- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view 
    calloutAccessoryControlTapped:(UIControl *)control开发者_JAVA百科


That is a delegate method of the map view so your code does not call it directly. The map view calls that method when an annotation view's rightCalloutAccessoryView or leftCalloutAccessoryView is tapped.

When creating the map view, set its delegate property and in the viewForAnnotation method, create a button and set it as the rightCalloutAccessoryView or leftCalloutAccessoryView.

For example:

- (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...
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜