MKMapView:获取注释图钉上的点击事件

发布于 2024-08-08 15:14:32 字数 380 浏览 3 评论 0原文

我使用的 MKMapView 包含几个 MKAnnotation 引脚。
在地图上方,我显示了一个 UITableView,其中包含 MKAnnotation 引脚的详细信息。

我的问题:当我选择一个引脚时,我想选择相应的表格单元格。 为此,如果选择了引脚,我想捕获一个事件/委托。我不是在谈论调用标注附件

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

I am using an MKMapView containing a couple of MKAnnotation pins.
Above the map I am showing a UITableView with detailed information of the MKAnnotation pins.

My problem: When I select a pin, I would like to select the corresponding table cell.
For this I would like to catch an event/delegate if the pin is selected. I am not talking about calling the callout accessory

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

冬天旳寂寞 2024-08-15 15:14:32

只是对此的更新 - 在 iOS 4 中,有 MKMapViewDelegate 方法可用于跟踪注释选择和取消选择:

- (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view
- (void)mapView:(MKMapView *)mapView didDeselectAnnotationView:(MKAnnotationView *)view

Just an update to this -- in iOS 4 there are MKMapViewDelegate methods that can be used to track annotation selection and de-selection:

- (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view
- (void)mapView:(MKMapView *)mapView didDeselectAnnotationView:(MKAnnotationView *)view
浅语花开 2024-08-15 15:14:32

您可以使用选定事件的观察者:

[pin addObserver:self
      forKeyPath:@"selected" 
         options:NSKeyValueObservingOptionNew
         context:@"ANSELECTED"];

- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context{

    NSString *action = (NSString*)context;

    if([action isEqualToString:@"ANSELECTED"]){

        BOOL annotationAppeared = [[change valueForKey:@"new"] boolValue];
        if (annotationAppeared) {
            // clicked on an Annotation
        }
        else {
            // Annotation disselected
        }
    }
}

you can use an Observer for Selected-Event:

[pin addObserver:self
      forKeyPath:@"selected" 
         options:NSKeyValueObservingOptionNew
         context:@"ANSELECTED"];

- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context{

    NSString *action = (NSString*)context;

    if([action isEqualToString:@"ANSELECTED"]){

        BOOL annotationAppeared = [[change valueForKey:@"new"] boolValue];
        if (annotationAppeared) {
            // clicked on an Annotation
        }
        else {
            // Annotation disselected
        }
    }
}
桜花祭 2024-08-15 15:14:32

我还没有在 MapKit 中看到一个简单的方法来做到这一点。委托上没有 mapView:annotationWasTapped:

一种方法是提供您自己的注释视图子类。自定义注释视图可以捕获 setSelected:animated: 或较低级别事件处理程序中的引脚选择,并将该信息传递到视图控制器。

I haven't seen a simple way to do this in MapKit. There's no mapView:annotationWasTapped: on the delegate.

One way to do it would be to provide your own annotation view subclass. The custom annotation view could capture the pin selection in setSelected:animated: or in a lower level event handler and pass that information up to your view controller.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文