title: UIImage not updating on setImage on button IBAction
body: <p>So I am changing the Image of a button and the Image of a UIImageView using these two functions:</p>
  
  <pre><code>- (IBAction)changeButton:(id)sender {
  
  
      //switch image to group if it is a badge. switch image to badge if it is a group.
  
      if([[properties objectForKey:@"current_item"] isEqualToString:@"badge"]){
          NSLog(@"reaching badge");
          UIImage *imageToSet = [UIImage imageNamed:current_group_image];
          [changeButtonOutlet.imageView setImage:imageToSet];
          [properties setObject:@"group" forKey:@"current_item"];
      } else {
          if([[properties objectForKey:@"current_item"] isEqualToString:@"group"]){
              NSLog(@"reaching group");
              UIImage *imageToSet = [UIImage imageNamed:current_badge_image];
              [changeButtonOutlet.imageView setImage:imageToSet];         
              [properties setObject:@"badge" forKey:@"current_item"];
  
          } 
      }
  
      [self switchBadgeImage];
  }
  
  -(void)switchBadgeImage{
      if([[properties objectForKey:@"current_item"] isEqualToString:@"badge"]){
          [badgeImageView setImage:[UIImage imageNamed:current_badge_image ]];
      } else {
      if([[properties objectForKey:@"current_item"] isEqualToString:@"group"]){
          [badgeImageView setImage:[UIImage imageNamed:current_group_image ]];    
      }
      }
  
  }
  </code></pre>
  
  <p>However the images dont update. If I spam the changeButton IBAction I can sometimes very quickly see the images changing but it always flicks back to the default one (just for the button). </p>
  
  <p>Here is what my console log tells me when I press the button repeatedly:</p>
  
  <pre><code>2012-08-24 12:20:52.414 MyApp[1448:707] reaching group
  2012-08-24 12:20:52.559 MyApp[1448:707] reaching badge
  2012-08-24 12:20:52.687 MyApp[1448:707] reaching group
  2012-08-24 12:20:52.846 MyApp[1448:707] reaching badge
  2012-08-24 12:20:52.976 MyApp[1448:707] reaching group
  2012-08-24 12:20:53.117 MyApp[1448:707] reaching badge
  2012-08-24 12:20:53.262 MyApp[1448:707] reaching group
  2012-08-24 12:20:53.348 MyApp[1448:707] reaching badge
  </code></pre>
  
  <p>What am I doing wrong? Thanks guys!</p>
  
  <hr>
  
  <p>EDIT: FIXED IT! Here is the updated code:</p>
  
  <p>-(void)switchBadgeImage{
      NSLog(@"current group image: %@", current_group_image);
      NSLog(@"current badge image: %@", current_badge_image);</p>
  
  <pre><code>current_item = [properties objectForKey:@"current_item"];
  
  if([current_item isEqualToString:@"badge"]){
      NSLog(@"current item is equal to badge");
      [badgeImage setImage:[UIImage imageNamed:current_badge_image ]];
  } else {
      if([current_item isEqualToString:@"group"]){
           NSLog(@"current item is equal to group");
          [badgeImage setImage:[UIImage imageNamed:current_group_image ]];    
      }
  }
  </code></pre>
  
  <p>}</p>
  
  <pre><code>- (IBAction)changeButton:(id)sender {
  
      //switch image to group if it is a badge. switch image to badge if it is a group.
  
      if([[properties objectForKey:@"current_item"] isEqualToString:@"badge"]){
          NSLog(@"reaching badge");
          UIImage *imageToSet = [UIImage imageNamed:current_badge_image];
          [changeButtonOutlet setImage:imageToSet forState:UIControlStateNormal];
          [properties setObject:@"group" forKey:@"current_item"];
          [properties synchronize];
      } else {
          if([[properties objectForKey:@"current_item"] isEqualToString:@"group"]){
              NSLog(@"reaching group");
              UIImage *imageToSet = [UIImage imageNamed:current_group_image];
              [changeButtonOutlet setImage:imageToSet forState:UIControlStateNormal];
              [properties setObject:@"badge" forKey:@"current_item"];
              [properties synchronize];
          } 
      }
  
      [self switchBadgeImage];
  
  
  }
  </code></pre>
  
  <p>There was a few problems actually. first I was switching the images the wrong way around. Secondly I was not synchronising the UserDefaults. I was also not updating the current_item variable after saving the current item to the UserDefaults. </p>
  
  <p>Thanks for all the help and so quickly!</p>