gpt4 book ai didi

cocoa-touch - 知道要使用哪个MKAnnotation的干净解决方案?

转载 作者:行者123 更新时间:2023-12-04 02:57:19 25 4
gpt4 key购买 nike

好的,因此通常在MKMapView中有一些要注释的对象X。您可以这样进行:

DDAnnotation *annotation = [[DDAnnotation alloc] initWithCoordinate: poi.geoLocation.coordinate title: @"My Annotation"];
[_mapView addAnnotation: annotation];

然后在里面创建注释 View
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation;

当一些标注被点击时,您可以在内部处理事件:
- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control;

将X传递给最新的Tap事件的最干净的解决方案是什么?

最佳答案

如果我理解您的问题,则应将引用或属性添加到DDAnnotation类,以便在calloutAccessoryControlTapped方法中可以访问该对象。

@interface DDAnnotation : NSObject <MKAnnotation> {
CLLocationCoordinate2D coordinate;
id objectX;
}
@property (nonatomic, readonly) CLLocationCoordinate2D coordinate;
@property (nonatomic, retain) id objectX;

创建注释时:
DDAnnotation *annotation = [[DDAnnotation alloc] initWithCoordinate:poi.geoLocation.coordinate title: @"My Annotation"];
annotation.objectX = objectX;
[_mapView addAnnotation: annotation];

然后:
- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control{

DDAnnotation *anno = view.annotation;
//access object via
[anno.objectX callSomeMethod];
}

关于cocoa-touch - 知道要使用哪个MKAnnotation的干净解决方案?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2329654/

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