0

我需要将从 webService 获取的自定义图像设置为 mapPins。为此,我在方法中编写了一个特定的代码

   - (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation
{
    NSLog(@"viewForAnnotation Method");

    if([annotation isKindOfClass:[MKUserLocation class]])
        return nil;

    NSString *annotationIdentifier = @"CustomViewAnnotation";
    MKAnnotationView* annotationView = [objMapView dequeueReusableAnnotationViewWithIdentifier:annotationIdentifier];
    if(!annotationView)
    {
        annotationView = [[MKAnnotationView alloc] initWithAnnotation:annotation
                                                      reuseIdentifier:annotationIdentifier];
    }

    //annotationView.canShowCallout= YES;


    NSLog(@"Annotation Index = %lu",(unsigned long)[mapView.annotations indexOfObject:annotation]);
    Annotations *myCustomPinAnnot = (Annotations*)annotation;
    NSLog(@"Selected title = %@",myCustomPinAnnot.title);

    if ([myCustomPinAnnot.title isEqualToString:@" TOWER PLACE"]) {
        arrayFromArray = [[NSMutableArray alloc] init];

        NSString *eff0 = [[allDataArray objectAtIndex:0] pinEfficiencyObjectClass];
        NSString *eff1 = [[allDataArray objectAtIndex:1] pinEfficiencyObjectClass];
        NSString *eff2 = [[allDataArray objectAtIndex:2] pinEfficiencyObjectClass];
        NSString *eff3 = [[allDataArray objectAtIndex:3] pinEfficiencyObjectClass];

        [self calculateEfficiency:eff0 andSecondEff:eff1 andThirdEff:eff2 andFourthEff:eff3];

        [arrayFromArray addObject:[allDataArray objectAtIndex:2]];
        [arrayFromArray addObject:[allDataArray objectAtIndex:1]];
        [arrayFromArray addObject:[allDataArray objectAtIndex:0]];
        [arrayFromArray addObject:[allDataArray objectAtIndex:3]];

        joinString=[NSString stringWithFormat:@"%@%@%@",@"mais_",[self getColourCode:eff0 andSecondEff:eff1      andThirdEff:eff2 andFourthEff:eff3],@".png"];

        NSLog(@"Join String = %@",joinString); //JoinString is the image fetched from web service
        UIImageView *imgV = [[UIImageView alloc] initWithImage:[UIImage imageNamed:joinString]];
        [imgV setFrame:CGRectMake(0, 0, 40, 40)];

        annotationView.image = imgV.image;

    }
return annotationView;

}

我得到一个带有相应图像的 4 个引脚。

现在,当我单击特定的图钉时,我可以将数据带到下一个视图,但图像不同。也就是说,如果我单击标题为“abc”的图钉,我会在下一个屏幕上成功显示标题。但是,如果图钉上的图像是红色的,那么下一个视图上的图像就不同了。

只有第一个和最后一个引脚的图像在下一个视图中正确显示。

第二个它给了我第一个图像,第三个它给了我最后一个图钉的图像。

诡异的。

我的 didSelectAnnotationCode。

-(void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view {

    Annotations *annView = view.annotation; 
    NSLog(@"Pin title in callout = %@",annView.pinTitle);
    objOnClickPinView = [[onClickPinView alloc]initWithNibName:@"onClickPinView" bundle:nil];

    objOnClickPinView.pinTitleString = annView.pinTitle;

    [self presentViewController:objOnClickPinView animated:YES completion:nil];

}

注意:我不需要显示 calloutView。我需要点击 mapPin 直接导航。

4

1 回答 1

2

我得到了错误。我发布这个答案只是因为如果在不久的将来你们中的某个人可能会面临同样的愚蠢问题。

i 传递给下一个视图的连接字符串被之前的视图覆盖,因此它包含虚拟数据。我通过输入相同的代码来解决这个问题

-(void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view {

并使用

- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control

那编译器将如何知道哪个引脚被窃听了。

因此我使用了 4 个不同的 joinStrings 而不是一个,并且在检查 didSelect 中的条件时

if ([annView.title isEqualToString:@"xyz"]) {
        objOnClickPinView.getColorCode = joinString1;
    }

else if...
于 2013-10-24T07:08:37.637 回答