2011-04-25 11 views

答えて

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... 
} 
関連する問題