Ios 抛出奇数异常的地理编码器

Ios 抛出奇数异常的地理编码器,ios,objective-c,geocoding,Ios,Objective C,Geocoding,我有一个方法,按下按钮就会触发。这是大部分实施: [self.placeDictionary setValue:@"166 Bovet Rd" forKey:@"Street"]; [self.placeDictionary setValue:@"San Mateo" forKey:@"City"]; [self.placeDictionary setValue:@"CA" forKey:@"State"]; [self.placeDictionary setValue

我有一个方法,按下按钮就会触发。这是大部分实施:

[self.placeDictionary setValue:@"166 Bovet Rd" forKey:@"Street"];
    [self.placeDictionary setValue:@"San Mateo"  forKey:@"City"];
    [self.placeDictionary setValue:@"CA" forKey:@"State"];
    [self.placeDictionary setValue:@"94402" forKey:@"ZIP"];

    CLGeocoder *geocoder = [[CLGeocoder alloc] init];
    [geocoder geocodeAddressDictionary:self.placeDictionary completionHandler:^(NSArray *placemarks, NSError *error) {
        if([placemarks count]) {
            CLPlacemark *placemark = [placemarks objectAtIndex:0];
            CLLocation *location = placemark.location;
            CLLocationCoordinate2D coordinate = location.coordinate;
            PFGeoPoint* userLocation = [PFGeoPoint geoPointWithLatitude:coordinate.latitude longitude:coordinate.longitude];
            NSLog(@"%f,%f", userLocation.latitude, userLocation.longitude); 
        } else {
            NSLog(@"location error");
            return;
        }
    }];
但是,我得到以下例外情况:

*** WebKit discarded an uncaught exception in the webView:shouldInsertText:replacingDOMRange:givenAction: delegate: <NSUnknownKeyException> [<__NSDictionaryI 0x873a3c0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key Street.
***WebKit丢弃了webView中未捕获的异常:shouldInsertText:replacingDOMRange:givenAction:delegate:[setValue:forUndefinedKey:]:此类不符合key Street的键值编码。

我完全不知道这个例外意味着什么。有人能帮我理解它为什么要生产这个吗

首先,您尝试将对象添加到不可变字典中。异常开始的部分
[setValue:forUndefinedKey:
给出了
\uu NSDictionaryI
的类名,它是
NSDictionary
类集群的不可变成员-因此在运行时无法向其添加任何对象。您需要确保在此代码之前将
self.placeDictionary
分配给
NSMutableDictionary
实例被称为

不幸的是,您也使用了错误的方法来添加对象-您使用的是
setValue:forKey:
而不是
setObject:forKey:
。由于此方法是
NSKeyValueCoding
非正式协议的一部分,因此在编译时不会阻止您这样做。您应该改用
setObject:forKey:
这是在
NSMutableDictionary
上设置键值对的正确方法。更正第一个问题后,将
setValue:forKey:
调用替换为
setObject:forKey:
,例如:

[self.placeDictionary setObject:@"San Mateo"  forKey:@"City"];

尝试将placeDictionary属性的声明从NSDictionary更改为NSMutableDictionary。