title: MKAnnotation pin color update
body: <p>In my app I am displaying a tableview which contains result of searched user from database. Now in that tableview there is one button by clicking on that user can see location of all searched users in map.when user first click on button he will be able to see all user's location with green color pin. I am displaying map in half part of view. Now When user select any particular searched user from table I want to change color of that user's pin.And if user select any other user from table previous selected user's pin color should be changed to as it was before.
  I have tried this:</p>
  
  <pre><code>- (void)selectAnnotation:(id &lt; MKAnnotation &gt;)annotation animated:(BOOL)animated{
      MKPinAnnotationView *chng=[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:nil];
      chng.pinColor=MKPinAnnotationColorRed;
      NSLog(@"========&gt;selected");
   }
  </code></pre>
  
  <p>And I am calling this method when user select particular user from table.</p>
  
  <pre><code>CLLocationCoordinate2D CurrentCoordinateSingleUser;
  CurrentCoordinateSingleUser.latitude=[[singleUserPin objectAtIndex:1] doubleValue];
  CurrentCoordinateSingleUser.longitude=[[singleUserPin objectAtIndex:2] doubleValue];
  MapObjects   *map1=[[MapObjects alloc]initwithCoordinate:CurrentCoordinateSingleUser title:[singleUserPin objectAtIndex:0] subtitle:Nil];
  
  [userMap addAnnotation:map1];
  for (id&lt;MKAnnotation&gt; currentAnnotation in userMap.annotations) {       
      if ([currentAnnotation isEqual:annotationToSelect]) {
          [userMap selectAnnotation:currentAnnotation animated:FALSE];
      }
  } 
  </code></pre>
  
  <p>But here <code>selectAnnotation</code> is not working.</p>
  
  <p>UPDATE::</p>
  
  <pre><code>- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id&lt;MKAnnotation&gt;)annotation {
  
      if([annotation isKindOfClass:[MKUserLocation class]])
          return nil;
  
  
      static NSString *identifier = @"myAnnotation";
      MKPinAnnotationView * annotationView = (MKPinAnnotationView*)[userMap dequeueReusableAnnotationViewWithIdentifier:identifier];
      if([annotation isEqual:map1]){
          annotationView.pinColor = MKPinAnnotationColorRed;
  
      }
      else {
          if (!annotationView)
          {
  
              annotationView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:identifier];
  //            if(fromSelectedTab==TRUE){
  //            annotationView.pinColor = MKPinAnnotationColorRed;
  //            annotationView.animatesDrop = NO;
  //            fromSelectedTab=FALSE;
  //            }
  //            else{
              annotationView.pinColor = MKPinAnnotationColorGreen;
              annotationView.animatesDrop = NO;
  //            }
              annotationView.canShowCallout = YES;
  
                  // annotationView.dr
          }
          else {
              annotationView.annotation = annotation;
          }
      }
      //annotationView.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
      return annotationView;
  }
  </code></pre>
  
  <p>MapObjects.h:</p>
  
  <pre><code>@interface MapObjects : NSObject&lt;MKMapViewDelegate,MKAnnotation&gt;
  {
      NSString *title,*subtitle;
      CLLocationCoordinate2D coordinate;
  }
  @property(nonatomic,copy)NSString *title;
  @property(nonatomic,copy)NSString *subtitle;
  @property(nonatomic) CLLocationCoordinate2D coordinate;
  -(MapObjects *)initwithCoordinate:(CLLocationCoordinate2D)coordinate title:(NSString    *)title subtitle:(NSString *)subtitle;
  
  @end
  </code></pre>