非同期要求が完了した後、カスタムMKAnnotationView
画像を更新する方法を見つけ出すのに問題があります。注釈のステータスに関する情報が含まれています。後MapKit update注釈画像
- (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;
}
これはエラー(私が貼り付けられたとすべてを正しくtraduced仮定)を立ち上げるありませんが、NSMutableDictionary私のカスタムMKAnnotationViewとMKAnnotationの両方が含まれているべきであるが、要求が完了すると、それが表示される前に、私はそれらをすべてログに記録しても正しく、要求があるとき私はMKAnnotationViewとMKAnnotationの両方が私が期待したものではないので、画像を変更したり注釈ビューを更新するために注釈を変更することはできません。
いずれかのアイデアをいただければ幸いです!
ありがとうございました!私はあなたの推薦に従い、後でまた報告します。 – Roberto
これはまさに私がする必要がありました、ありがとうございました! – Roberto