場所のタイトル、説明、日付、場所の名前など、MKAnnotationに詳細を追加したいと思います。したがって、必要なのは4行になります。しかし、タイトルとサブタイトルの2つのパラメーターのみをMKAnnotationに渡すことができることがわかりました。マップに詳細を追加するにはどうすればよいですか?Plzは私を助けます..事前に感謝します。
28949 次
1 に答える
15
カスタムMKAnnotationView
オブジェクトの作成を見てみましょう。これは基本的に、UIView
マップ アノテーション用に調整された です。そのオブジェクトには、4 つのカスタム ラベルを含めることができます。
MKMapViewDelegate
クラスで、次のviewForAnnotation
メソッドを実装します。
- (CustomMapAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation
{
CustomMapAnnotationView *annotationView = nil;
// determine the type of annotation, and produce the correct type of annotation view for it.
CustomMapAnnotation* myAnnotation = (CustomMapAnnotation *)annotation;
NSString* identifier = @"CustomMapAnnotation";
CustomMapAnnotationView *newAnnotationView = (CustomMapAnnotationView *)[self.mapView dequeueReusableAnnotationViewWithIdentifier:identifier];
if(nil == newAnnotationView) {
newAnnotationView = [[[CustomMapAnnotationView alloc] initWithAnnotation:myAnnotation reuseIdentifier:identifier] autorelease];
}
annotationView = newAnnotationView;
[annotationView setEnabled:YES];
[annotationView setCanShowCallout:YES];
return annotationView;
}
これにより、注釈がある場所にカスタム ビューが表示されます。ステップ バイ ステップのチュートリアルが必要な場合は、このビデオをご覧ください。
お役に立てれば
編集
Apple 開発サイトで実際に新しいマップの例を見つけたところです...必要なすべてのソースコードがあります。彼らはまた、MKAnnotationView
と呼ばれるカスタムを使用していますWeatherAnnotationView
于 2010-02-26T15:33:29.953 に答える