NSMutableArray
当我尝试使用带有该信息的注释时,我有一个带有地图坐标的注释,我在注释行上收到此错误。坐标,它在 IOS 5 和 6 上工作:
-[__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;
}