ios - 更改MKMapView上的注释图钉颜色

标签 ios objective-c parse-platform mkmapview mkpointannotation

我正在尝试通过覆盖以下内容来更改MKMapView上注释针的颜色:

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation
{
// If it's the user location, just return nil.
if ([annotation isKindOfClass:[MKUserLocation class]])
    return nil;

// Handle any custom annotations.
if ([annotation isKindOfClass:[MKPointAnnotation class]])
{
    MKPinAnnotationView *pinView = (MKPinAnnotationView*)[mapView dequeueReusableAnnotationViewWithIdentifier:@"CustomPinAnnotationView"];
    if (!pinView)
    {
        pinView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"CustomPinAnnotationView"];
        pinView.canShowCallout = YES;
        pinView.pinColor = MKPinAnnotationColorGreen;
    } else {
        pinView.annotation = annotation;
    }
    return pinView;
}
return nil;
}

以下是相关方法:
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.

[self configureView];
}


- (void)configureView
{
// Update the user interface for the detail item.
if (self.detailItem) {

    // display map ????
    PFGeoPoint *geoPoint = self.detailItem[@"location"];
    CLLocationCoordinate2D coordinate = CLLocationCoordinate2DMake(geoPoint.latitude,geoPoint.longitude);

    MKPointAnnotation *annotation =[[MKPointAnnotation alloc] init];
    annotation.coordinate = coordinate;

    // remove previous annotation pin
    if([self.mapView.annotations count] == 1) {
        [self.mapView removeAnnotation:[self.mapView.annotations objectAtIndex:0]];
    }

    [self.mapView addAnnotation:annotation];
    annotation.title = self.detailItem[@"text"];

    MKCoordinateSpan span = {.latitudeDelta =  0.05, .longitudeDelta =  0.05};
    MKCoordinateRegion region = {coordinate, span};
    [self.mapView setRegion:region];

    [self.mapView setCenterCoordinate:self.mapView.region.center animated:NO];

}

}

我的问题是,引脚注释颜色仍然显示为默认的红色而不是我想要的绿色。我在这里想念什么?

最佳答案

感谢@Anna,将以下行添加到-(void)configureView

self.mapView.delegate = self;

关于ios - 更改MKMapView上的注释图钉颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27468749/

相关文章:

ios - 在应用程序启动时关闭邮件编辑器

ios - 核心数据模型规划

parse-platform - 使用 PFQuery 获取 PFObjects 时,它不会返回完整的对象

javascript - 弹性转码器 AWS 从 Parse.com CloudCode Javascript http 请求创建作业

iphone - 在您旋转之前,后退按钮不会出现在导航栏中

ios - 自定义标记图标 iOS 质量差

ios - SKSpriteNode 不会居中

ios - iOS 应用程序内的新 field ?

ios - NSPredicate 和 NSArray

ios - 如何使用对象列中的值作为 wherekey?