実際、私は自分のアプリ内に注釈を表示するものを開発しています。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 *)control
UIButtonのセレクター(ただし、IDを渡す方法は?)または(再びIDを渡す方法は?)のいずれかを使用して、disclosureButtonのタップを処理できると思いました。
私が言いたいことを理解していただければ幸いです。あなたの答えを前もって感謝します! :)