我有一個問題,找出在異步請求完成後更新自定義MKAnnotationView
圖像的方式,並附上關於註釋狀態的信息。到目前爲止,我有這樣的:MapKit更新註釋圖像
- (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,但即使我請求之前登錄他們都完成了,它似乎正確的時候,請求est完成了它,好像MKAnnotationView和MKAnnotation都不是我所期望的那樣,因此我無法修改註釋來更改圖像或更新註釋視圖。
任何想法,將不勝感激!
謝謝!我會按照您的建議並在稍後報告。 – Roberto
這正是我需要做的,非常感謝你! – Roberto