我需要将从 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 个图钉。
现在,当我点击一个特定的图钉时,我能够将数据带到下一个 View ,但图像不同。 也就是说,如果我单击标题为“abc”的图钉,我会在下一个屏幕上成功显示标题。 但是,如果图钉上的图像是红色的,那么下一个 View 中的图像就会不同。
只有第一个和最后一个图钉的图像在下一个 View 中正确显示。
第二次它给我第一张图片,第三次它给我最后一个图钉的图片。
奇怪。
我的 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 直接导航。
最佳答案
我得到了错误。 我发布这个答案只是因为如果在不久的将来你们中的某个人可能会遇到同样的愚蠢问题。
我传递给下一个 View 的连接字符串被它的前一个覆盖了,因此它包含了虚拟数据。 我通过在
中放入相同的代码来解决这个问题-(void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view {
并使用
- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control
编译器将如何知道哪个引脚被窃听了。
因此我使用了 4 个不同的 joinStrings 而不是一个,并在 didSelect as 中检查条件
if ([annView.title isEqualToString:@"xyz"]) {
objOnClickPinView.getColorCode = joinString1;
}
else if...
关于ios - 将特定注释的数据带到下一个 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19557836/