MKAnnotationView不显示标注

时间:2011-11-17 14:42:14

标签: cocoa-touch

我正在尝试让MKMapView显示带有标注气泡的图钉。我得到了要显示的引脚,但我无法弄清楚如何显示标注。

有我的代码:

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id)annotation {
    if (annotation == mapView.userLocation) {
        return nil;
    }
    MKPinAnnotationView *pinView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"Pin"];
    pinView.pinColor = MKPinAnnotationColorGreen;
    [pinView setCanShowCallout:YES];
    pinView.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
    pinView.animatesDrop = YES;
    [self performSelector:@selector(displayPinCallOutView) withObject:nil afterDelay:0.3];
    return pinView;
}

1 个答案:

答案 0 :(得分:5)

如果您尝试在将注释添加到地图后立即显示标注,则必须使用didAddAnnotationViews委托方法执行此操作:

-(void)mapView:(MKMapView *)mapView didAddAnnotationViews:(NSArray *)views
{
    //Get reference to annotation you want to select...
    //You could search through mapView.annotations array
    //or keep ivar reference to it.
    id<MKAnnotation> annToSelect = ...

    [mapView selectAnnotation:annToSelect animated:YES];
}

performSelector方法中删除viewForAnnotation