この質問は以前に他の人から尋ねられたことを知っており、以前にこのフォーラムでそれらを読んだことがありますが、提案されたすべてのアプローチをこれまで運がなかったため、この質問を投稿することにしました。
MKMapViewのピンアイコンを変更するためのコードを以下に示します。ただし、viewForAnnotation 関数は MKMapView によって呼び出されるようには見えません。.xib ファイルのマップ ビューをファイルの所有者にドラッグするか、myMap.delegate = self を定義することで実行できるファイルの所有者に関数を委任する際に問題が発生したと人々は言いました。両方の方法を実行しましたが、まだ何も得られません。
私の問題を解決していただき、本当にありがとうございます。
コード:
- (MKPinAnnotationView*)myMap:(MKMapView*)myMap viewForAnnotation:(id<MKAnnotation>)annotation{
MKPinAnnotationView *pin = [[MKPinAnnotationView alloc]initWithAnnotation:annotation reuseIdentifier:@"CustomPin"];
UIImage *icon = [UIImage imageNamed:@"bustour.png"];
UIImageView *iconView = [[UIImageView alloc] initWithFrame:CGRectMake(8,0,32,37)];
if(icon == nil)
NSLog(@"image: ");
else
NSLog(@"image: %@", (NSString*)icon.description);
[iconView setImage:icon];
[pin addSubview:iconView];
pin.canShowCallout = YES;
pin.pinColor = MKPinAnnotationColorPurple;
return pin;
}
委任