MapView注释

时间:2011-03-22 07:58:29

标签: iphone map

我在注释视图上添加了一个图像,当我触摸注释视图时,它的图像变为红色图钉可以任何人告诉我他的理由是什么

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation 
{
    MKPinAnnotationView* newAnnotation = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"annotation1"];

    if (annotation == _mapView.userLocation)
    {
        newAnnotation.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
        return nil;
    }

    //[newAnnotation setSelected:YES];
    newAnnotation.image = [UIImage imageNamed:@"sample.png"];
    newAnnotation.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
    newAnnotation.canShowCallout = YES;
    [newAnnotation retain];

    return newAnnotation;

}

1 个答案:

答案 0 :(得分:1)

newAnnotation成为MKAnnotationView而不是MKPinAnnotationView