3

MKPinAnnotationView上の注釈ピンを使用していMKMapViewます。私が開発しているビューには、ピンを中心としたマップがあります。ビューを呼び出すと、ピンがドロップダウンし、クリックすると、注釈情報が表示されます(canShowCallout = YES)。ビューを開いたときにこのコールアウトを取得するにはどうすればよいですか?注釈ピンをクリックせずに。

読んでくれてありがとう。

編集:

私はこのコードを使用しています。

- (void)viewDidLoad {

    [super viewDidLoad];

    AddressAnnotation *annotation = [[[AddressAnnotation alloc] initWithCoordinate:self.currentAnnotationCoordinate] autorelease];
    [self.mapView addAnnotation:annotation];
    [self zoomCoordinate:self.currentAnnotationCoordinate];
}

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

    // If it's the user location, just return nil.
    if ([annotation isKindOfClass:[MKUserLocation class]])
        return nil;
    else { // Handles the other annotations.
        // Try to dequeue an existing pin view first.
        static NSString *AnnotationIdentifier = @"AnnotationIdentifier";
        MKPinAnnotationView *pinView = (MKPinAnnotationView *)[self.mapView dequeueReusableAnnotationViewWithIdentifier:AnnotationIdentifier];

        if (!pinView) {
            // If an existing pin view was not available, creates one.
            MKPinAnnotationView *customPinView = [[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:AnnotationIdentifier] autorelease];
            customPinView.animatesDrop = YES;
            customPinView.canShowCallout = YES;

            // Adds a detail disclosure button.
            UIButton *rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
            [rightButton addTarget:self action:@selector(showDetails:) forControlEvents:UIControlEventTouchUpInside];
            customPinView.rightCalloutAccessoryView = rightButton;

            return customPinView;
        } else
            pinView.annotation = annotation;
    }

    return nil;
}


- (void)mapViewDidFinishLoadingMap:(MKMapView *)theMapView {

    AddressAnnotation *annotation = [[[AddressAnnotation alloc] initWithCoordinate:self.currentAnnotationCoordinate] autorelease];

    for (id<MKAnnotation> currentAnnotation in mapView.annotations) {       
        if ([currentAnnotation isEqual:annotation]) {
            [mapView selectAnnotation:currentAnnotation animated:FALSE];
        }
    }
}

編集:

(aBitObviousがコメントしているように)didAddAnnotationViews:代わりに呼び出すと、正常に機能します。mapViewDidFinishLoadingMap:

- (void)mapView:(MKMapView *)mapView didAddAnnotationViews:(NSArray *)views {

    id<MKAnnotation> myAnnotation = [self.mapView.annotations objectAtIndex:0];
    [self.mapView selectAnnotation:myAnnotation animated:YES];
}
4

1 に答える 1

3

重複の可能性:ピンに触れずにMKAnnotationViewのコールアウトビューをトリガーするにはどうすればよいですか?

呼び出したい[mapView selectAnnotation:]

于 2010-11-19T19:02:29.373 に答える