我的程序执行 buttonPressed 方法并执行 if else 语句,但我的按钮上的文本仍然没有改变。有什么我错过的吗?我什至已经在 xib 中对其进行了自定义,但是即使进入另一个语句,buttonPlayMusic 的文本仍保持为“播放”。
我想我也连接了按钮。
[viewDidLoad]
{
self.buttonPlayMusic = [UIButton buttonWithType:UIButtonTypeRoundedRect];
self.buttonPlayMusic.frame = CGRectMake(((scrollView.frame.size.width - 200) / 2) + cx, 360, 200, 50);
[self.buttonPlayMusic setTitle:@"Play" forState:UIControlStateNormal];
[self.buttonPlayMusic addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside];
self.toggleButonPlayMusic = YES; //YES to play, NO to stop music
[scrollView addSubview:self.buttonPlayMusic];
}
-(IBAction)buttonPressed:(id)sender{
NSLog(@"SSS");
if (self.toggleButonPlayMusic == YES) {
[self.buttonPlayMusic setTitle:@"Stop" forState:UIControlStateNormal];
self.toggleButonPlayMusic = NO;
NSLog(@"RRR");
}else{
[self.buttonPlayMusic setTitle:@"Play" forState:UIControlStateNormal];
self.toggleButonPlayMusic = YES;
NSLog(@"ZZZ");
}
}