0

次のコードを使用して、右のアクセサリ ボタンで注釈吹き出しを作成しています

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

if ([annotation isKindOfClass:[MKUserLocation class]]){
    return nil;
}

else {

    static NSString *AnnotationViewID = @"annotationViewID";

    MKAnnotationView *annotationView = (MKAnnotationView *)[self.mapView dequeueReusableAnnotationViewWithIdentifier:AnnotationViewID];

    if (annotationView == nil)
    {
        annotationView = [[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:AnnotationViewID];
    }

    annotationView.image = [UIImage imageNamed:@"Mevents.png"];
    annotationView.annotation = annotation;
    annotationView.canShowCallout=YES;

    UIButton* rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
    [rightButton setTitle:annotation.title forState:UIControlStateNormal];
    [rightButton addTarget:self action:@selector(showDetails:) forControlEvents:UIControlEventTouchUpInside];

    annotationView.rightCalloutAccessoryView = rightButton;

    //  UIImageView *profileIconView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"profile.png"]];
    //  pinView.leftCalloutAccessoryView = profileIconView;
    //  [profileIconView release];

    return annotationView;

}

}

どの注釈がクリックされたかを追跡するにはどうすればよいですか? 詳細画面にIDをロードし、その ID に基づいてデータを取得して情報を表示したいと考えています。

4

2 に答える 2

0

When you create the annotation add a tag to it

annotationView.image = [UIImage imageNamed:@"Mevents.png"];
//Add this after
annotationView.tag = 111;

Now in viewForAnnotation, check for this tag

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

if ([annotation isKindOfClass:[MKUserLocation class]]){
    return nil;

    if(annotation.tag == 111)
        //Do something
    else
        //Do some other thing
}
于 2012-06-18T09:42:48.323 に答える
0

ねえ、次のスレッドで私の答えをチェックしてください。

マップビューで注釈がタップされたときにデータを detailView に渡す

于 2012-06-18T10:03:35.500 に答える