我有地图的坐标NSMutableArray
当我尝试使用注释与信息我正在上线annotation.coordinate这个错误,它正在对iOS 5和6:IOS 7误差与注释
- [__ NSCFArray objectForKeyedSubscript:]:无法识别的选择发送到实例
我有这样的代码:
NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:@"URL"]];
NSError *error;
NSArray *array = [NSJSONSerialization JSONObjectWithData:data
options:0
error:&error];
NSString *value = [array valueForKey:@"cortesMap"];
NSMutableArray *arr = [[NSMutableArray alloc] init];
[arr addObject:value];
if (error)
{
NSLog(@"%s: error=%@", __FUNCTION__, error);
return;
}
for (NSDictionary *dictionary in arr)
{
MKPointAnnotation *annotation = [[MKPointAnnotation alloc] init];
annotation.coordinate = CLLocationCoordinate2DMake([dictionary[@"latitude"] doubleValue], [dictionary[@"longitude"] doubleValue]);
annotation.title = dictionary[@"type"];
annotation.subtitle = dictionary[@"description"];
[self.mapView addAnnotation:annotation];
}
这里是viewForAnnotation
:
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation
{
MKAnnotationView *annotationView= nil;
if (![annotation isKindOfClass:[MKUserLocation class]])
{
static NSString *annotationViewId = @"annotationViewId";
annotationView = (MKAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:annotationViewId];
if (annotationView == nil)
{
annotationView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:annotationViewId];
annotationView.canShowCallout = YES;
annotationView.image = [UIImage imageNamed:@"pin.png"]
}
else
{
annotationView.annotation = annotation;
}
}
return annotationView;
}
带有错误的行是annotation.coordinate与经度和纬度,我用nslog检查数组,并且它具有我想要的正确信息。 – dastjuso
@dastjuso'dictionary'对象真的是'NSDictionary'吗?没有。 – Rob
我为字典添加了一行新的代码,但仍然出现相同的错误。 – dastjuso