开发者

setImage:forState: does not work in iOS 3.2

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 me开发者_如何学JAVAaning 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


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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜