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」というタイトルのピンをクリックすると、次の画面にタイトルが正常に表示されます。ただし、ピンの画像がたとえば赤の場合、次のビューの画像は異なります。
次のビューでは、最初と最後のピンの画像のみが正しく表示されています。
2 番目の画像では最初の画像が表示され、3 番目の画像では最後のピンの画像が表示されます。
変。
私の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 をクリックして直接移動する必要があります。