1

ピンをクリックせずにピンにコールアウトを表示しようとしています。要するに、ピンがマップに配置されているときにコールアウトを表示したいのです。

これは私が使用しているコードです:

-(MKAnnotationView*)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation         //  Method to handle all the annotations on map.
{

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

    static NSString *annotationID = @"MyAnnotation";

    MKPinAnnotationView *pinView = (MKPinAnnotationView*)[mapView dequeueReusableAnnotationViewWithIdentifier:annotationID] ;

    if (!pinView) {
        pinView = [[MKPinAnnotationView alloc]initWithAnnotation:annotation reuseIdentifier:annotationID];
        pinView.canShowCallout = YES;
        pinView.image = [UIImage imageNamed:@"map_pin.png"];

        //Setting Right call button
        pinView.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];

        //Setting Left Call button
        self.favButton = [UIButton buttonWithType:UIButtonTypeCustom];
        self.favButton.frame = CGRectMake(0, 0, 23, 23);
        self.favButton.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
        self.favButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
        [self.favButton setImage:[UIImage imageNamed:@"favourite.png"] forState:UIControlStateNormal];
        pinView.leftCalloutAccessoryView = self.favButton;

        [self.mapView selectAnnotation:annotation animated:YES];
    }
    return pinView;

}

どんな助けもかなりのものです。

4

1 に答える 1

0

これで試してください:

- (void)mapView:(MKMapView *)mapView didAddAnnotationViews:(NSArray *)views{
    for (id<MKAnnotation> currentAnnotation in mapView.annotations) {
        if ([currentAnnotation isEqual:annotationToSelect]) {
            [mapView selectAnnotation:currentAnnotation animated:YES];
        }
    }
}

また

EDIT : -(MKAnnotationView*)mapView:(MKMapView *)mapView viewForAnnotation:(id)annotation // マップ上のすべての注釈を処理するメソッド。{

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

static NSString *annotationID = @"MyAnnotation";

MKPinAnnotationView *pinView = (MKPinAnnotationView*)[mapView dequeueReusableAnnotationViewWithIdentifier:annotationID] ;

if (!pinView) {
    pinView = [[MKPinAnnotationView alloc]initWithAnnotation:annotation reuseIdentifier:annotationID];
    pinView.canShowCallout = YES;
    pinView.image = [UIImage imageNamed:@"map_pin.png"];

    //Setting Right call button
    pinView.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];

    //Setting Left Call button
    self.favButton = [UIButton buttonWithType:UIButtonTypeCustom];
    self.favButton.frame = CGRectMake(0, 0, 23, 23);
    self.favButton.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
    self.favButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
    [self.favButton setImage:[UIImage imageNamed:@"favourite.png"] forState:UIControlStateNormal];
    pinView.leftCalloutAccessoryView = self.favButton;

            **[self performSelector:@selector(selectAnnotation:) withObject:annotation afterDelay:0.5];**

}
return pinView;

}

- (void)selectAnnotation:(id < MKAnnotation >)annotation
{
    [self.mapView selectAnnotation:annotation animated:NO];
}
于 2013-07-01T10:34:29.983 に答える