【问题标题】:MKMapView NSUnknownKeyException [duplicate]MKMapView NSUnknownKeyException [重复]
【发布时间】:2012-10-20 10:18:02
【问题描述】:

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

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

【问题讨论】:

  • 检查 MapViewController xib 中的 IBOutlets 是否都连接正确。

标签: objective-c mkmapview mkannotationview


【解决方案1】:

我在您显示的代码中看不到它,但是您是否尝试在控制器上的某个地方设置 mapview 但未将其设置为属性?也许你在声明中使用了错误的名字,你打电话给viewcontroller.mapView = ....

【讨论】:

    猜你喜欢
    • 2011-06-14
    • 2012-06-05
    • 2015-08-25
    • 1970-01-01
    • 2014-07-03
    • 1970-01-01
    • 2014-12-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多