【问题标题】:MKMapView didDeselectAnnotationView interaction with UITableViewMKMapView didDeselectAnnotationView 与 UITableView 交互
【发布时间】:2011-10-21 07:43:27
【问题描述】:

我的一个视图中有一个 MKMapView,上面有一些注释。还有一个隐藏的 UITableView,每个单元格显示每个注释的详细信息。当用户选择某个注释时,会出现 tableView 并选择特定的单元格。此外,当用户选择一个单元格时,特定的注释也会被选中。

I want the view to have the following behavior: when an annotation is selected and the user taps the map the tableView will disappear but when the user selects another annotation the tableView will stay visible and changes the selected index.

问题在于didDeselectAnnotationView 方法。它在didSelectAnnotationView 之前被调用,所以在您要检查的方法中:

-  (void)mapView:(MKMapView *)mapview didSelectAnnotationView:(MKAnnotationView *)view
{
     if([mapView.selectedAnnotations count] == 0)
         [self hideTableView];
}

目前没有选中的注解,tableView 总是被隐藏。

我的问题是didDeselectAnnotationView 是否有办法区分点击的地图和选择另一个注释。

另外,有什么解释为什么在 iPhone 3G(4.2.1) 中didDeselectAnnotationViewdidSelectAnnotationView 之后被调用?看起来很奇怪!

提前谢谢你!

【问题讨论】:

    标签: objective-c ios xcode uitableview mkmapview


    【解决方案1】:

    我的处理方法如下......

    - (void)mapView:(MKMapView *)mapview didDeselectAnnotationView:(MKAnnotationView *)view {
      [self performSelector:@selector(hideMyTableView) withObject:nil afterDelay:0.1];
    }
    
    - (void)mapView:(MKMapView *)mapview didDeselectAnnotationView:(MKAnnotationView *)view {
      [NSObject cancelPreviousPerformRequestsWithTarget:self];
    }
    

    它的作用是将 hideMyTableView 的调用排队 0.1 秒,如果 didSelect 方法触发它会取消此请求并且您的代码可以执行它需要执行的操作,如果 didSelect 没有被调用,则将调用 hideMyTableView .您可能需要将 0.1 增加到 0.5,但请先尝试 0.1。

    【讨论】:

    • 谢谢西蒙,它似乎可以满足我的需要。关于第二个问题(关于 iPhone3G)的任何想法?再次感谢您!
    • 由于调用是线程化的,它可能是手机的性能问题,或者可能是特定操作系统中的不同代码优化,很难说,但你的代码应该能够处理这两种情况,因为你从来没有知道线程瓶颈何时可能会改变通知的顺序。
    猜你喜欢
    • 2012-03-11
    • 1970-01-01
    • 1970-01-01
    • 2010-11-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-03-03
    相关资源
    最近更新 更多