0

プロパティ(NameTableとID)を指定したカスタムアノテーションが多数あります。作成時にAddAnnotationの前にこのプロパティを設定しましたが、デリゲートメソッドのこれらのプロパティは表示されなくなりました。データベースから取得したテーブルの要素に関連付けられた複数の注釈があります。デリゲートメソッドでそれらを表示するにはどうすればよいですか?

 - (void)viewDidLoad
{

     //......

   for(int i=0; i<6; i++){ //loop for create multiple annotations

   AnnotationCustom *annotationIcone =[[AnnotationCustom alloc]initWithCoordinates:coord 
               title:self.myTable.title subTitle:self.myTable.address];

        annotationIcone.nameTable = [NSString stringWithFormat:@"%@", self.myTableName];
        annotationIcone.ID = i+1;

    [self.mapView addAnnotation: annotationIcone;

     //.....
   }

しかし、デリゲートメソッドでは:

  (MKAnnotationView *)mapView:(MKMapView *)mapview viewForAnnotation:(id 
   <MKAnnotation>)annotation
    {

     NSLog(@"The name of table is:@"%@", annotation.nameTable);
     //property 'nameTable' not found on object of type '_strong id <MKAnnotation>

     NSLog (@The name of table is:@%@", annotation.ID);
     //property 'ID' not found on object of type '_strong id <MKAnnotation>

         //......
     }

別の方法では:

    - (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view{

       NSLog(@"The name of table is %@", self.myTableName);
       // here I get the name of last table open and not the name of table selected


      }
4

1 に答える 1

2

viewForAnnotationでは、注釈が実際にはAnnotationCustomオブジェクトであることをコンパイラーに通知する必要があります。

したがって、最初にこれを行う必要があります。

AnnotationCustom *annotationCustom = (AnnotationCustom *)annotation;

次に、nameTableプロパティにアクセスしてみます。

didSelectAnnotationViewメソッドで、選択した注釈のnameTable値を取得する必要がある場合は、次の手順を実行する必要があります。

AnnotationCustom *annotationCustomSelected = (AnnotationCustom *)view.annotation;
NSLog(@"table name of annotation selected: %@", annotationCustomSelected.nameTable);
于 2012-11-09T10:23:33.347 に答える