干净的解决方案来知道哪个 MKAnnotation 已被窃听?
好的,所以您通常有一些想要在 MKMapView 内注释的对象 X。您可以这样做:
DDAnnotation *annotation = [[DDAnnotation alloc] initWithCoordinate: poi.geoLocation.coordinate title: @"My Annotation"];
[_mapView addAnnotation: annotation];
然后您在内部创建注释视图
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation;
当某些标注被点击时,您可以在内部处理事件:
- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control;
将 X 传递到最新点击事件的最干净的解决方案是什么?
Ok, so you typically have some object X you want to be annotated inside a MKMapView. You do this way:
DDAnnotation *annotation = [[DDAnnotation alloc] initWithCoordinate: poi.geoLocation.coordinate title: @"My Annotation"];
[_mapView addAnnotation: annotation];
Then you create the annotation view inside
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation;
And when some callout gets tapped, you handle the event inside:
- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control;
What's the cleanest solution to pass X down to the latest tap event?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果我理解您的问题,您应该向 DDAnnotation 类添加引用或属性,以便在 calloutAccessoryControlTapped 方法中您可以访问该对象。
当您创建注释时:
然后:
If I'm understanding your question, you should add a reference or property to your DDAnnotation class so that in your calloutAccessoryControlTapped method you can access the object.
When you create the annotation:
Then:
我这样做了并且效果很好!
这正是我所需要的,因为我需要在点击地图时执行某些操作,但让点击正常进入注释流。
I did this and it worked alright!
It's exactly what I need because I needed to do something when the map was tapped but letting the tap into the annotation flow normally.