title: Check if user has selected another annotation in map
body: <p>I have a map with annotations where I am performing the following actions:</p>
  
  <pre><code>- (void)mapView:(MKMapView *)mapView didDeselectAnnotationView:(MKAnnotationView *)view{
  [self methodA];}
  
  
   - (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view{
  [self methodB];}
  </code></pre>
  
  <p>Both method A and B remove or add views in mapView.superview. </p>
  
  <p>All works fine when dealing with one annotation. <strong>The Problem is when I have more than one annotation and I select two, one after the other</strong>.</p>
  
  <p>If I click anywhere else in the map everything works fine. But when I click in the second annotationview after the first one, it performs "didDeselectAnnotationView" and then "didSelectAnnotationView" which calls both methods A and B, and it is not what I want. I would like it to detect that I am clicking in another annotation and ignore both methods.  </p>
  
  <p>I have researched about this but haven't found any solution yet. </p>
  
  <p>I have tried to add an global variable and play with it as well as identifying where the user touches: </p>
  
  <pre><code>-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
  
  UITouch *touch = [touches anyObject];
  
  // Get the specific point that was touched
  CGPoint point = [touch locationInView:self.mapView];
  
  for (id&lt;MKAnnotation&gt; annotation in self.mapView.annotations) {
      MKAnnotationView* anView = [self.mapView viewForAnnotation: annotation];
      if (anView){
  
          CGRect frame = CGRectMake(anView.frame.origin.x-5, anView.frame.origin.y-5, anView.frame.size.width+5, anView.frame.size.height+5);
          if ( CGRectContainsPoint(frame, point) ) {
  
              NSLog(@"BELONGS");
          }
  
      }
  
  }}
  </code></pre>
  
  <p>However, this didn't catch all the touches plus it would be a bit of a spaghetti solution. </p>
  
  <p>Any ideas how to solve this?</p>
  
  <p>All the best</p>