我的一个视图中有一个MKMapView,上面有一些注释。还有一个hiden UITableView,每个单元格都显示每个注释的详细信息。当用户选择某个注释时,将显示tableView并选择特定单元格。此外,当用户选择单元格时,会选择特定的注释。
我希望视图具有以下行为:当选择注释并且用户点击地图时,tableView将消失,但是当用户选择另一个注释时,tableView将保持可见并更改所选索引。
问题在于didDeselectAnnotationView
方法。它会在didSelectAnnotationView
之前调用,因此在您要检查的方法中:
- (void)mapView:(MKMapView *)mapview didSelectAnnotationView:(MKAnnotationView *)view
{
if([mapView.selectedAnnotations count] == 0)
[self hideTableView];
}
此刻没有选定的注释,并且tableView始终隐藏。
我的问题是didDeselectAnnotationView
是否有办法区分点击的地图和另一个注释的选择。
另外,有没有解释为什么iPhone 3G(4.2.1)didDeselectAnnotationView
被didSelectAnnotationView
后调用?这看起来很奇怪!
提前谢谢!
答案 0 :(得分: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。