2

実際、私は自分のアプリ内に注釈を表示するものを開発しています。MKMapViewこれらの注釈はクリック可能で、メソッドにパラメーターを渡す必要があります。
今のところ問題は、公開ボタンをタップしたときに次の関数にパラメータを渡す方法です。
注釈の書式設定には、- (MKAnnotationView *)mapView:(MKMapView *)aMapView viewForAnnotation:(id <MKAnnotation>)annotationメソッドを使用して開示ボタンを表示します。しかし問題は、Annotation現在表示されているオブジェクトから値を取得する方法です。

私のコードAnnotation(関連部分のみ):

@synthesize coordinate, id, title, subtitle;

+ (id)annotationWithCoordinate:(CLLocationCoordinate2D)coordinate {
    return [[[[self class] alloc] initWithCoordinate:coordinate] autorelease];
}

- (id)initWithCoordinate:(CLLocationCoordinate2D)coordinate {
    self = [super init];

    if(nil != self) {
        self.coordinate = coordinate;
    }

    return self;
}

そして、開示ボタンをタッチしたときに- (void)displayInfo:(NSNumber *) anId;、引き渡しをパラメーターとしてメソッドを呼び出す必要がありAnnotation.idますanId

開示ボタンは、そのコードで生成されます。

   UIButton *disclosureButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];

    dropPin.rightCalloutAccessoryView = disclosureButton;
    dropPin.animatesDrop = YES;
    dropPin.canShowCallout = YES;

だから - 質問:
どうすればそのパラメータを関数に渡すかid、クリックされたのを読むことができますAnnotationか?

- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)controlUIButtonのセレクター(ただし、IDを渡す方法は?)または(再びIDを渡す方法は?)のいずれかを使用して、disclosureButtonのタップを処理できると思いました。

私が言いたいことを理解していただければ幸いです。あなたの答えを前もって感謝します! :)

4

1 に答える 1

4

calloutAccessoryControlTapped では、ビューを介して注釈を使用できます。

MKAnnotation *annotation = view.annotation;
于 2010-12-22T13:41:55.230 に答える