更改pincolor后无法显示注释标题

时间:2012-04-11 10:27:52

标签: ios annotations mkmapview mkpinannotationview

我使用此代码更改注释的颜色,但在此之后,标题和副标题无法显示,如何保存此问题?

代码是:

- (MKAnnotationView *)mapView:(MKMapView *)mV viewForAnnotation:(id <MKAnnotation>)annotation 
{   
  static NSString *defaultPinID = @"LYB"; 
    MKPinAnnotationView *customPinview = (MKPinAnnotationView *)[_mapView dequeueReusableAnnotationViewWithIdentifier:defaultPinID]; 
    if ( customPinview == nil ) {
        customPinview = [[[MKPinAnnotationView alloc] 
                    initWithAnnotation:from reuseIdentifier:defaultPinID] autorelease]; 
    }
    if ([annotation isKindOfClass:[MKUserLocation class]])
        return nil;
    if ([[annotation title] isEqualToString:@"the first"]) {
        customPinview.pinColor = MKPinAnnotationColorGreen;
    }
    return customPinview;
}

1 个答案:

答案 0 :(得分:2)

在“return customPinview”之前在新行中添加以下代码:

customPinview.canShowCallout = YES;