1

あなたが私を助けてくれることを願っています。私は学校の宿題に取り組んでおり、オブジェクトの配列を取り、マップ上のそれらのオブジェクトからマップ アノテーションを作成するプロジェクトを作成する必要があります。私のオブジェクトには 2 つの値があります。1 つは NSString *title で、もう 1 つは coord と呼ばれる cllocationcoordinate2d です。配列からそれらのオブジェクトを取得して、マップ ビューにマップ アノテーションを設定する for ループがあります。

私の質問は次のとおりです。私の割り当てでは、配列から特定のオブジェクトを削除するオプションがあり、マップビューでそれらの削除されたオブジェクトを注釈から削除する必要があります。すべての注釈をクリアして、削除されたオブジェクトを除いてそれらを再作成することは想定されていません。つまり、 for ループで作成された特定のアノテーションをそのメソッドの外から選択する方法があるかどうか疑問に思っています。注釈オブジェクトにカスタム id 引数を作成する必要がありますか?

コードを貼り付けますが、何を表示する必要があるのか​​ 正確にはわかりません. また、この質問があいまいまたはわかりにくい場合はお詫び申し上げます。私はこれまでこのサイトを実際に使用したことはありませんし、実際に質問をする必要があったこともありません. 前もって感謝します。

4

3 に答える 3

0

削除する注釈をどのように選択しますか? アクセサリ コントロール (ピンをタップするとポップアップするウィンドウの右側にある小さなアイコン) をタップして行う場合は、注釈への参照を取得して、次のようにマップから削除できます。

- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control
{
    MKAnnotation *tappedAnnotation = view.annotation;
    [mapView removeAnnotation:tappedAnnotation];
}

参照: MKMapViewdelegate

于 2013-02-21T19:31:15.520 に答える
0

このコードを試して、

NSMutableArray *annotationsToRemove = [[NSMutableArray alloc] init];

 for (int i = 0; i < [mapView.annotations count]; i++) {

    NSString *anonotationTitle = [[mapView.annotations objectAtIndex:i] title];

    if([annotationTitle isEqualToString:@"titleToDelete"]){
        [annotationsToRemove addObject:[mapView.annotations objectAtIndex:i]];
    }

 }

 [mapView removeAnnotations:annotationsToRemove];
于 2013-02-21T07:59:10.217 に答える
0

わかりました。 のカスタム注釈サブクラスを作成できますMKAnnotationView

例えば:

MyCustomAnnotationView.h

#import <Foundation/Foundation.h>
@class MKAnnotationView;

@interface MyCustomAnnotationView : MKAnnotationView
@property (nonatomic, strong) NSString* customId;

@end

MainViewController.m

...
- (MKAnnotationView *)mapView:(MKMapView *)theMapView viewForAnnotation:(id <MKAnnotation>)annotation
{
    static NSString* annotationIdentifier = @"annotationIdentifier";
    MyCustomAnnotationView* annotationView =
    (MyCustomAnnotationView *)[self.mapView dequeueReusableAnnotationViewWithIdentifier:SFAnnotationIdentifier];
    annotationView.customId = [dataSource title];
    ....
}
....

customIdプロパティによってデータソースから彼を削除します

于 2013-02-21T08:10:52.097 に答える