1

我想在每次添加注释时显示图钉的标题(MKAnnotation)。我为此添加了以下代码。但它不起作用。请帮我找出答案。我刚刚添加了这样的引脚。

ann = [[DisplayMap alloc] init];
ann.title = @"aaa";
ann.subtitle = @"bbbn";
[mapView addAnnotation:ann];

之后我在这个方法中添加了以下代码

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

    if(annotation != mapView.userLocation) 
    {
        static NSString *defaultPinID = @"com.invasivecode.pin";
        pinView = (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:defaultPinID];
        if ( pinView == nil ) 
            pinView = [[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:defaultPinID] autorelease];

        pinView.pinColor = MKPinAnnotationColorRed; 
        pinView.canShowCallout = YES;
        pinView.animatesDrop = YES;
        pinView.selected = YES;
        [mapView selectAnnotation:annotation animated:YES];

        //[pinView setImage:[UIImage imageNamed:@"user.png"]];

    }
}

我犯了什么错误?

4

0 回答 0