-1

也许这个问题已经被问过了,但我找不到它。我得到的错误真的让我头疼!

Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<MapViewController 0x8095670> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key mapView.'

我认为这是设置注释并调用事件的时间。我的代码:

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

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

    MKPinAnnotationView *annotationView = 
    (MKPinAnnotationView *)[myMapView 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 *rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
    [rightButton setTitle:annotation.title forState:UIControlStateNormal];
    [annotationView setRightCalloutAccessoryView:rightButton];

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

    return annotationView;
}

return nil; 
}

我是 ObjC 的新手。但是,如果您需要任何代码以进行更多检查,我很乐意将其发送给您!

4

1 回答 1

0

我在您显示的代码中看不到它,但是您是否尝试在控制器上的某个地方设置 mapview 但没有将其设置为属性?也许您在声明中使用了错误的名称并且您正在调用viewcontroller.mapView = ....

于 2012-10-22T03:17:57.680 回答