I have a MKMapView in one of my views with some annotations on it. There is also a hiden UITableView with each cell presenting details of each annotation. When the user selects a certain annotation, the tableView appears and the specific cell gets selected. Also, when a user selects a cell the specific annotation gets selected.
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.
The problem is with the didDeselectAnnotationView method. It gets called before didSelectAnnotationView so when in the method you want to check:
- (void)mapView:(MKMapView *)mapview didSelectAnnotationView:(MKAnnotationView *)view
{
if([mapView.selectedAnnotations count] == 0)
[self hideTableView];
}
there is no selected annotation at the moment and the tableView gets always hidden.
My question is whether there is a way for the didDeselectAnnotationView to distinguish between the map tapped and the selection of another annotation.
Also, is there any explanation why in an iPhone 3G(4.2.1) didDeselectAnnotationView gets called AFTER didSelectAnnotationView? It seems pretty strange!
Thank you in advance!
The way I would approach this is as follows….
What this does it queues up the calling of hideMyTableView for 0.1 seconds, IF the didSelect method fires it cancels this request and your code can do what it needs to do, if the didSelect DOESN’T get called then hideMyTableView will be called. You may need to increase 0.1 to 0.5 but try 0.1 first.