问题描述
实际上,我已经从Web服务中检索了很多有关服务站的信息,它们在这里,我为每个站显示了一个图钉注释,以UIButtonTypeDetailDisclosure
的形式显示在地图上,现在我要存储每个图钉都有一些其他信息,例如:
actually, i have retrieved a lot of informations about service stations from web-service, they are here, i displayed for each Station a pin annotation to show it on the Map with a UIButtonTypeDetailDisclosure
, now i want to store for each pin some additional informations like :
float lng = [[stationEnCours objectForKey:@"ssiphone_longitude"] floatValue];//that's how i retrieve it from web-service
float lat = [[stationEnCours objectForKey:@"ssiphone_latitude"] floatValue];//that's how i retrieve it from web-service
出于我的目的,我使用委托的这种众所周知的方法:
for my purpose, i use this well known method of the delegate :
-(void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control
{
NSLog(@"calloutAccessoryControlTapped");
//how to do to store additional informations
}
但是我有点受阻,我该如何存储与每个引脚相关的其他信息,请帮忙,任何建议,示例代码,教程将不胜感激:)))))))
but i am some kind blocked, how can i store additional informations related to each pin, help please, any suggestions, sample code, tutorials will be appreciated :))))) thx in advance
推荐答案
是的,在MyLocation.h(实现MKAnnotation的类)中声明所有属性.创建注释时,在调用addAnnotation
之前,请设置属性.
Yes, declare all your properties in MyLocation.h (the class that implements MKAnnotation). When creating annotations and before calling addAnnotation
, set the properties.
在calloutAccessoryControlTapped
中,获得如下所示的属性(示例使用上一个问题中定义的MyLocation中的属性):
In calloutAccessoryControlTapped
, get the properties like this (example uses properties in MyLocation defined in your previous question):
- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control
{
MyLocation *myLoc = (MyLocation *)view.annotation;
NSLog(@"calloutAccessoryControlTapped: enseigneDeLaStation = %@, distanceVersLaStation=%@", myLoc.enseigneDeLaStation, myLoc.distanceVersLaStation);
}
这篇关于如何在MKPinAnnotation中存储与引脚相关的信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!