MKAnnotationView
非同期リクエストが注釈のステータスに関する情報で完了した後に、カスタム イメージを更新する方法を見つけるのに問題があります。これまでのところ、私はこれを持っています:
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation {
static NSString *identifier = @"EstacionEB";
if ([annotation isKindOfClass:[EstacionEB class]]) {
EstacionEB *location = (EstacionEB *) annotation;
CustomPin *annotationView = (CustomPin *) [_mapita dequeueReusableAnnotationViewWithIdentifier:identifier];
if (annotationView == nil) {
annotationView = [[CustomPin alloc] initWithAnnotation:annotation reuseIdentifier:identifier];
} else {
annotationView.annotation = annotation;
}
UIImage * image = [UIImage imageNamed:[NSString stringWithFormat:@"%@.png", [location elStatus]]];
annotationView.enabled = YES;
annotationView.canShowCallout = YES;
annotationView.image = image;
NSDictionary *temp = [[NSDictionary alloc]
initWithObjects:[NSArray arrayWithObjects:annotationView, location, nil]
forKeys:[NSArray arrayWithObjects:@"view", @"annotation", nil]
];
//This array is synthesized and inited in my controller's viewDidLoad
[self.markers setObject:temp forKey:location.eid];
return annotationView;
}
return nil;
}
その少し後、リクエストを実行し、その結果である NSDictionary を使用して、次のことを実行しようとしています。これにより、両方の要素に null が返されます。
- (void)updateStation:(NSString *)eid withDetails:(NSDictionary *)details
{
NSInteger free = [details objectForKey:@"free"];
NSInteger parkings = [details objectForKey:@"parkings"];
NSDictionary *storedStations = [self.markers objectForKey:eid];
CustomPin *pin = [storedStations objectForKey:@"view"]; //nil
EstacionEB *station = [referencia objectForKey:@"annotation"]; //nil as well
[station setSubtitle:free];
NSString *status;
if( free==0 ){
status = @"empty";
} else if( (free.intValue>0) && (parkings.intValue<=3) ){
status = @"warning";
} else {
status = @"available";
}
UIImage * image = [UIImage imageNamed:[NSString imageWithFormat:@"%@.png", status]];
pin.image = image;
}
これによりエラーは発生しません(すべてを正しく貼り付けて変換したと仮定します)が、カスタム MKAnnotationView と MKAnnotation の両方を含む必要がある NSMutableDictionary ですが、リクエストが完了する前にそれらをすべてログに記録し、リクエストが完了すると正しく表示されます。 MKAnnotationView と MKAnnotation の両方が私が期待したものではないかのように、注釈を変更して画像を変更したり、注釈ビューを更新したりすることはできません。
どんなアイデアでも大歓迎です!