title: iOS custom Icons for map annotations randomizing
body: <p>On my map view I am loading in locations from json. (works great)</p>
  
  <p>In my json I have a node called 'type' which helps set the image in viewForAnnotation (works great)</p>
  
  <p>I have a set of radio buttons which removes all annotations then reloads only certain ones based on type (works great - sorta)</p>
  
  <p>This issue is when the radio buttons are pushed all the data is correct however the icons get all rearranged (looks random).  This title, subtitle, phone, and type are all still correct.  </p>
  
  <p>It looks like when the buttons are pushed viewForAnnotaion is not being fired. Nothing is logging in that method at least. But thats only place the icons are being set.  I am lost on this one. </p>
  
  <p><strong>CODE</strong></p>
  
  <pre><code>- (void)whichPins:(int)t {
  
      for(id key in json) {
          id value = [json objectForKey:key];
          NSString *address = [value valueForKey:@"address"];
          NSString *latitude = [value valueForKey:@"latitude"];
          NSString *longitude = [value valueForKey:@"longitude"];
  
          NSArray* foo = [address componentsSeparatedByString: @":"];
          NSString* address2 = [foo objectAtIndex: 0];
          phone = [foo objectAtIndex: 1];
  
          double myLatitude = [latitude doubleValue];
          double myLongitude = [longitude doubleValue];
  
          MKCoordinateRegion location1;
          location1.center.latitude = myLatitude;
          location1.center.longitude = myLongitude;
          location1.span.longitudeDelta = 0.1;
          location1.span.latitudeDelta = 0.1;
  
          ann1 = [[[MapAnnotation alloc] init] autorelease];
          ann1.title = [NSString stringWithFormat:@"%@",[value valueForKey:@"title"]];
          ann1.subtitle = [NSString stringWithFormat:@"%@",address2];
          ann1.phone = [NSString stringWithFormat:@"%@",phone];
          ann1.coordinate = location1.center;
          ann1.type = [value valueForKey:@"type"];
  
          if (t == 0) {
              [mapView addAnnotation:ann1];
          } else if (t == 1 &amp;&amp; [ann1.type isEqualToString:@"1"]) {
              [mapView addAnnotation:ann1];
          } else if (t == 2 &amp;&amp; [ann1.type isEqualToString:@"2"]) {
              [mapView addAnnotation:ann1];
          } else if (t == 3) {
              if ([ann1.type isEqualToString:@"0"] || [ann1.type isEqualToString:@"3"] || [ann1.type isEqualToString:@"4"]) {
                  [mapView addAnnotation:ann1];
              }
          } else {}
  
          //NSLog(@"Title: %@ , type: %@", ann1.subtitle, ann1.type);
  
          [phone retain];
          [json retain];
      }
      //NSLog(@"/////////////////////////////////////////////////////////////////");
  }
  
  - (MKAnnotationView *)mapView:(MKMapView *)mapView2 viewForAnnotation:(id&lt;MKAnnotation&gt;)annotation {
  
      if ([annotation isKindOfClass:[MKUserLocation class]])
          return nil;
      static NSString* AnnotationIdentifier = @"AnnotationIdentifier";
      MKAnnotationView *annotationView = [mapView dequeueReusableAnnotationViewWithIdentifier:AnnotationIdentifier];
      if(annotationView)
          return annotationView;
      else {
          MKAnnotationView *annotationView = [[[MKAnnotationView alloc] initWithAnnotation:annotation
                                                                           reuseIdentifier:AnnotationIdentifier] autorelease];
          annotationView.canShowCallout = YES;
          annotationView.draggable = NO;
  
          if (![((MapAnnotation *)annotation).phone isEqualToString: @"0"]) {
              UIButton* rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
              [rightButton setImage:[UIImage imageNamed:@"map_phone_icon"] forState:UIControlStateNormal];
              [rightButton addTarget:self action:@selector(button:) forControlEvents:UIControlEventTouchUpInside];
              [rightButton setTitle:annotation.title forState:UIControlStateNormal];
              annotationView.rightCalloutAccessoryView = rightButton;
          }
          if ([((MapAnnotation *)annotation).type isEqualToString: @"0"]) {
              annotationView.image = [UIImage imageNamed:@"popomap.png"];
          } else if ([((MapAnnotation *)annotation).type isEqualToString: @"1"]) {
              annotationView.image = [UIImage imageNamed:@"robbery.png"];
          } else if ([((MapAnnotation *)annotation).type isEqualToString: @"2"]) {
              annotationView.image = [UIImage imageNamed:@"other.png"];
          } else if ([((MapAnnotation *)annotation).type isEqualToString: @"3"]) {
              annotationView.image = [UIImage imageNamed:@"firemap.png"];
          } else if ([((MapAnnotation *)annotation).type isEqualToString: @"4"]) {
              annotationView.image = [UIImage imageNamed:@"doctormap.png"];
          }
  
  
          return annotationView;
      }
      return nil;
  }
  
  - (IBAction)onRadioBtn:(RadioButton*)sender {
      [mapView removeAnnotations:mapView.annotations];
  
      if ([sender.titleLabel.text isEqualToString:@"All"]) {
          rbtnType = 0;
      }
      if ([sender.titleLabel.text isEqualToString:@"Crime"]) {
          rbtnType = 1;
      }
      if ([sender.titleLabel.text isEqualToString:@"Other"]) {
          rbtnType = 2;
      }
      if ([sender.titleLabel.text isEqualToString:@"Stations"]) {
          rbtnType = 3;
      }
      [self whichPins:rbtnType];
  }
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/H6jni.png" alt="on load pic">
  <img src="https://i.stack.imgur.com/MPc8u.png" alt="after all is hit"></p>