このコードを使用して、カスタム注釈ビューを作成します。
- (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:
ボタンにタグを追加して処理できると思いますが、レストランの配列があり、コンクリートのピンをタップすると現在のレストランを表示する必要があるため、選択する最善の方法が必要です。したがって、この場合のタグは、私が思うほど便利ではありません。