我有地圖的座標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