0

我正在尝试在 Annotation 上添加一个按钮,但在线出现错误:

MKPinAnnotationView *annotationView = (MKPinAnnotationView *)[MapView dequeueReusableAnnotationViewWithIdentifier:identifier];

这表明:

选择器 dequeueReusableAnnotationViewWithIdentifier 没有已知的类方法。

我真的不知道如何解决它我感谢任何帮助。

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

static NSString *identifier = @"MyLocation";
if ([annotation isKindOfClass:[MapAnnotation class]]) {

    MKPinAnnotationView *annotationView = (MKPinAnnotationView *)[MapView dequeueReusableAnnotationViewWithIdentifier:identifier];

    if (annotationView == nil) {
        annotationView = [[MKPinAnnotationView alloc] 
                          initWithAnnotation:annotation 
                          reuseIdentifier:identifier];
    } else {
        annotationView.annotation = annotation;
    }

    annotationView.enabled = YES;
    annotationView.canShowCallout = YES;

    // Create a UIButton object to add on the 

    UIButton *leftButton = [UIButton buttonWithType:UIButtonTypeInfoDark];
    [leftButton setTitle:annotation.title forState:UIControlStateNormal];
    [annotationView setLeftCalloutAccessoryView:leftButton];

    return annotationView;
}
}
4

1 回答 1

1

更改此行:

MKPinAnnotationView *annotationView = (MKPinAnnotationView *)[MapView dequeueReusableAnnotationViewWithIdentifier:identifier];

有了这个:

MKPinAnnotationView *annotationView = (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:identifier];

注意大写字母:

MapView 与 mapView 不同。

于 2012-11-11T21:11:29.340 回答