2014-07-01 28 views
0

我正在使用mapKit。我創建了帶標題,副標題和ID的自定義註釋。 這是創建的標註方法:如何獲得另一個類中的地圖註釋屬性?

- (instancetype) initWithCoordinates:(CLLocationCoordinate2D)paramCoordinates title: (NSString *)paramTitle subTitle:(NSString *)paramSubTitle ID:(NSString*)ID 
{ 
self = [super init]; 
if (self != nil) 
    { 
    _coordinate = paramCoordinates; _title = paramTitle; 
    _subtitle = paramSubTitle; 
    _ID = ID; 
    } 
return self; 
} 

現在我用這個在其他類中創建註釋:在單擊批註我希望能夠得到註解ID

-(void)createCityAnnotation 
{ 
CLLocationCoordinate2D location1 = 
CLLocationCoordinate2DMake(35.6961, 51.4231); 
mapAnnotation *annotation1 = 
[[mapAnnotation alloc] initWithCoordinates:location1 
            title:@"City 1" 
            subTitle:@"XXX" 
             ID:@"1"]; 
[self.myMapView addAnnotation:annotation1]; 

CLLocationCoordinate2D location2 = 
CLLocationCoordinate2DMake(32.6333, 51.6500); 
mapAnnotation *annotation2 = 
[[mapAnnotation alloc] initWithCoordinates:location2 
            title:@"City2" 
            subTitle:@"YYY" 
             ID:@"2"]; 
[self.myMapView addAnnotation:annotation2]; 

CLLocationCoordinate2D location3 = 
CLLocationCoordinate2DMake(38.0667, 46.3000); 
mapAnnotation *annotation3 = 
[[mapAnnotation alloc] initWithCoordinates:location3 
            title:@"City3" 
            subTitle:@"WWW" 
             ID:@"3"]; 
[self.myMapView addAnnotation:annotation3]; 
} 

現在在calloutAccessoryControlTapped方法中。我不知道到底該怎麼做so.It會是這樣的:

- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control 
{ 
    ////Use the Annotations ID here. 
    [table reloadData]; 
} 
+0

檢查view.annoatation正在恢復與否。 –

+0

我NSLog view.annotation,這是我得到: devdev101

回答

1

嘗試這個

 - (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control 
     { 
      mapAnnotation *annotaion= view.annotation;//this annotationWill be ur annotation.then u can get ID by annotation.ID. 
NSLog(@"%@",annotation.ID); 
     } 
+0

我覺得這裏有一個誤解,ID是一個NSString! – devdev101

+0

你的要求是從這個方法得到的ID,R8? –

+0

如果你已經足夠了,請在答案 –

相關問題