Ios 如何在另一个类中获取map annotations属性?
我在用地图工具包。我创建了带有标题、副标题和ID的自定义注释。 这是创建注释的方法:Ios 如何在另一个类中获取map annotations属性?,ios,mapkit,mkannotationview,Ios,Mapkit,Mkannotationview,我在用地图工具包。我创建了带有标题、副标题和ID的自定义注释。 这是创建注释的方法: - (instancetype) initWithCoordinates:(CLLocationCoordinate2D)paramCoordinates title: (NSString *)paramTitle subTitle:(NSString *)paramSubTitle ID:(NSString*)ID { self = [super init]; if (self != nil) {
- (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;
}
现在我使用它在另一个类中创建注释:
-(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
方法中获得注释ID。我不知道该怎么做。应该是这样的:
- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control
{
////Use the Annotations ID here.
[table reloadData];
}
试试这个
- (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);
}
检查view.annotation是否正在返回。我将NSLog view.annotation返回,这是我得到的结果:我认为这里有一个误解,ID是NSString!您的要求是从该方法中获取ID,r8?如果足够,请在回答上打勾谢谢Suhail!你是个救生员