【发布时间】: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