1

The expected behavior is to change the image (from play to pause and from pause to play) when the play action is clicked. This works as expected in version 4.x. In version 3.2 the setImage does not work meaning the setImage does not set the image. Call to imageForState:UIControlStateNormal returns null in 3.2 version. Any ideas?

@interface TestViewController : UIViewController {
  IBOutlet UIButton *playButton;
  BOOL play;
}

- (IBAction) play:(id)sender;

@end


@implementation TestViewController

- (IBAction) play:(id)sender {  
  if (play == YES) {
    [playButton setImage:[UIImage imageNamed:@"pause"] forState:UIControlStateNormal];    
   play = NO;
  } else {
    [playButton setImage:[UIImage imageNamed:@"play"] forState:UIControlStateNormal];    
    play = YES;
  }
  //[playButton imageForState:UIControlStateNormal]

}

@end
user687888
  • 11
  • 1

2 Answers2

0

Your code looks correct, have you checked that you connected up the IBOutlet in your XIB file for your button?

Andrew
  • 690
  • 7
  • 11
0

UIImage's imageNamed takes in a image name with extension i.e if you change your code

[UIImage imageNamed:@"pause"]

to

[UIImage imageNamed:@"pause.png"] or [UIImage imageNamed:@"pause.jpg"]

your code will work as per your expectations.

atxe
  • 5,029
  • 2
  • 36
  • 50
Saurabh Passolia
  • 8,099
  • 1
  • 26
  • 41