iOS MapView抛出了一堆valueForUndefinedKey

时间:2014-01-11 05:11:21

标签: ios objective-c mkmapview

我在具有单点注释的应用程序中有一个简单的地图视图。代码非常简单:

[_mapView removeAnnotations:_mapView.annotations];
    CLGeocoder *geocoder = [[CLGeocoder alloc] init];
    NSString *addressString = [NSString stringWithFormat:@"%@, %@, %@, %@",self.event.address,self.event.city,self.event.state,self.event.zip];
    [geocoder geocodeAddressString:addressString completionHandler:^(NSArray* placemarks, NSError* error){
        dispatch_async(dispatch_get_main_queue(), ^{
            // Assume that the first placemark is the correct address (not sure if there's a better way around this, but in theory should only ever match one).
            CLPlacemark *address = [placemarks firstObject];
            // add a marker to the map for the address
            MKPointAnnotation *addressAnnotation = [[MKPointAnnotation alloc] init];
            addressAnnotation.coordinate = address.location.coordinate;
            addressAnnotation.title = _event.venue;
            [_mapView addAnnotation:addressAnnotation];
            MKMapPoint venuePoint = MKMapPointForCoordinate(address.location.coordinate);
            // get a default map rect
            MKMapRect mapRect = MKMapRectMake(venuePoint.x, venuePoint.y, 0.1, 0.1);
            if (showUser) {
                // zoom map to include address and user if the user has an address
                MKUserLocation *currentUserLocation = [_mapView userLocation];
                if (currentUserLocation && currentUserLocation.location) {
                    MKMapPoint userPoint = MKMapPointForCoordinate(currentUserLocation.location.coordinate);
                    mapRect = MKMapRectUnion(MKMapRectMake(userPoint.x, userPoint.y, 0.1, 0.1), mapRect);
                }
            }
            // zoom map rect out a little so we can see what's going on here as a user
            mapRect = [_mapView mapRectThatFits:mapRect edgePadding:UIEdgeInsetsMake(100, 100, 100, 100)];
            [_mapView setVisibleMapRect:mapRect animated:YES];
        });
    }];

然而,当我运行应用程序时,它会抛出一堆看起来像这样的错误:

<MKPinAnnotationView 0x23dadb90> valueForUndefinedKey:]: this class is not key value coding-compliant for the key subtitle.

应用程序没有崩溃,并且没有堆栈跟踪,因此我不知道错误发生的位置或原因。在这段代码附近没有任何东西叫做字幕,我假设错误与注释字幕有关吗?

不确定在哪里查找 - 我已经注释掉了上面的注释代码并且错误消失了,所以它与此代码有些相关。

0 个答案:

没有答案