gpt4 book ai didi

ios - 如何在另一个类中获取 map 注释属性?

转载 作者:行者123 更新时间:2023-11-29 02:51:09 25 4
gpt4 key购买 nike

我正在使用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;
}

现在我用它在另一个类中创建注释:

-(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。我不知 Prop 体该怎么做。大概是这样的:

- (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);
}

关于ios - 如何在另一个类中获取 map 注释属性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24510128/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com