0

このコードを使用して、カスタム注釈ビューを作成します。

- (MKAnnotationView *)mapView:(MKMapView *)mV viewForAnnotation:(id <MKAnnotation>)annotation {

    MKPinAnnotationView *pinAnnotation = nil;
    if(annotation != myMapView.userLocation) {
        static NSString *defaultPinID = @"myPin";
        pinAnnotation = (MKPinAnnotationView *)[myMapView dequeueReusableAnnotationViewWithIdentifier:defaultPinID];
        if ( pinAnnotation == nil )

            pinAnnotation = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:defaultPinID];

        pinAnnotation.canShowCallout = YES;

        //instatiate a detail-disclosure button and set it to appear on right side of annotation
        UIButton *infoButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
        [infoButton addTarget:self
                       action:@selector(showRestaurantDescription)
             forControlEvents:UIControlEventTouchUpInside];
        pinAnnotation.rightCalloutAccessoryView = infoButton;
    }    
    return pinAnnotation;
}

私の問題は、パラメーターをセレクターに送信する方法です: -showRestaurantDescription:

ボタンにタグを追加して処理できると思いますが、レストランの配列があり、コンクリートのピンをタップすると現在のレストランを表示する必要があるため、選択する最善の方法が必要です。したがって、この場合のタグは、私が思うほど便利ではありません。

4

1 に答える 1

2

mapView:annotationView:calloutAccessoryControlTapped:ボタンのタップをリッスンするには、デリゲートメソッドを使用する必要があります。そのメソッドは、プロパティannotationViewを持つanに渡されannotationます。アノテーションプロパティを使用して、それがどのレストランであったかを把握できます。

また、コロンを忘れましたaction:@selector(showRestaurantDescription)か?

于 2012-07-27T10:58:11.497 に答える