0

MKMapView を使用してインターフェイス ビルダーを使用してアプリケーションでマップを取得しようとしていますが、何らかの理由で表示されません。また、iPhoneに存在するファイルを参照できるボタンをクリックして、このビューにいくつかのボタンを追加したいと考えています。

私はこれに慣れていないので、詳細な説明を提供してください。

ありがとう、

4

2 に答える 2

1

マップに注釈を追加してから、カスタム ビューを提供します。

マップに注釈を追加するには、オブジェクトの 1 つでMKAnnotationプロトコルを採用し、その座標プロパティを適切な緯度/経度の位置に設定します。

次に、MKMapView addAnnotationを使用して注釈をマップに追加します。

マップのデリゲート プロパティをビュー コントローラーに設定してから、mapView:viewForAnnotationを実装します。

このメソッドが呼び出されると、注釈の MKAnnotationView を返します。MKAnnotationView のimageプロパティを、注釈で使用する任意の画像 (おそらくボタンの画像?) に設定します。

注釈がいつ選択されたかを知りたい場合は、mapView:didSelectAnnotationView:を実装できます。

MKAnnotationView のleftCalloutAccessoryViewおよびrightCalloutAccessoryViewプロパティを使用して、注釈に吹き出しアクセサリ ボタンを設定することもできます。これを行うと、mapView:annotationView:calloutAccessoryControlTapped:を実装することで、ユーザーが吹き出しボタンを選択したときに応答できます。

于 2010-07-21T21:54:57.823 に答える
0
- (MKAnnotationView *)mapView:(MKMapView *)map viewForAnnotation:(id <MKAnnotation>)annotation
{
    static NSString *AnnotationViewID = @"annotationViewID";

     annotationView = (MKAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:AnnotationViewID];

    if (annotationView == nil)
    {
        annotationView = [[[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:AnnotationViewID] autorelease];
    }
    annotationView.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
    annotationView.image = [UIImage imageNamed:@"s11.png"];

    annotationView.annotation = annotation;

    [annotationView setEnabled:YES];
    [annotationView setCanShowCallout:YES];

    return annotationView;
}
于 2010-07-22T13:51:52.003 に答える