我有地圖,而我添加多個註釋,像這樣:的MKMapView關閉屏幕標註圖像不正確
for (Users *user in mapUsers){
double userlat = [user.llat doubleValue];
double userLong = [user.llong doubleValue];
CLLocationCoordinate2D userCoord = {.latitude = userlat, .longitude = userLong};
MapAnnotationViewController *addAnnotation = [[MapAnnotationViewController alloc] initWithCoordinate:userCoord];
NSString *userName = user.username;
NSString *relationship = user.relationship;
[addAnnotation setTitle:userName];
[addAnnotation setRelationshipParam:relationship];
[self.mainMapView addAnnotation:addAnnotation];
}
使用該委託方法代碼:
-(MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation
{
static NSString *identifier = @"AnnotationIdentifier";
if ([annotation isKindOfClass:[MapAnnotationViewController class]]) {
MKAnnotationView *annView = (MKAnnotationView *)[self.mainMapView dequeueReusableAnnotationViewWithIdentifier:identifier];
if (!annView) {
annView = [[MKAnnotationView alloc] initWithAnnotation:annotation
reuseIdentifier:identifier];
}
MapAnnotationViewController *sac = (MapAnnotationViewController *)annView.annotation;
if ([sac.relationshipParam isEqualToString:@"paramA"])
{
annView.image = [UIImage imageNamed:@"image1.png"];
}
else if ([sac.relationshipParam isEqualToString:@"paramB"])
{
annView.image = [UIImage imageNamed:@"image2.png"];
}
else if ([sac.relationshipParam isEqualToString:@"paramC"])
{
annView.image = [UIImage imageNamed:@"image3.png"];
}
return annView;
}
else {
return nil;
}
這一切工作正常原始加載地圖。但是,當我選擇註釋(具有過長的發佈但包含放大的自定義代碼)時,先前繪製的註釋圖像已更改圖標。地圖不會重新繪製,註釋在該過程中不會重新添加。當我在地圖上縮回來時,圖像是不同的(它們具有不正確的關係params和錯誤的image1-3.png相匹配。
任何人都可以想到爲什麼會發生這種情況,或者尋找什麼?
大答案ANNA甚至很長一段時間後,幫助我 – raghul