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> 

     //...... 
    } 

또 다른 방법은 : viewForAnnotation에서

- (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 


     } 

답변

2

, 당신은 주석이 실제로 AnnotationCustom 개체입니다 컴파일러에게해야합니다. 당신이 원하는 것은의 nameTable 값을 얻을 경우, didSelectAnnotationView 방법에 있습니다 .. nameTable 속성에 액세스하려고 다음

AnnotationCustom *annotationCustom = (AnnotationCustom *)annotation; 

과 :

그래서 먼저 필요는이 작업을 수행하는 주석을 선택하면 다음을 수행해야합니다.

AnnotationCustom *annotationCustomSelected = (AnnotationCustom *)view.annotation; 
NSLog(@"table name of annotation selected: %@", annotationCustomSelected.nameTable); 
+0

감사합니다. –

+0

매우 간단하면서도 크게 감사하겠습니다! – CampbellGolf

관련 문제