その情報で注釈を使用しようとするNSMutableArray
と、マップ座標がありますが、このエラーが行 annotation.coordinate で発生しています。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;
}