MKMapView NSUnknownKeyException

时间:2012-10-20 10:18:03

标签: objective-c mkmapview mkannotationview

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

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的新手。但是如果您需要任何代码进行更多检查,我很乐意将其发送给您!

1 个答案:

答案 0 :(得分:0)

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