【发布时间】:2009-06-25 22:28:37
【问题描述】:
我正在通过Beginning iPhone Development 工作。书中是这样的方法:
-(void)playWinSound
{
NSString *path = [[NSBundle mainBundle] pathForResource:@"win" ofType:@"wav"];
SystemSoundID soundID;
AudioServicesCreateSystemSoundID((CFURLRef)[NSURL fileURLWithPath:path], &soundID);
AudioServicesPlaySystemSound (soundID);
winLabel.text = @"WIN!";
[self performSelector:@selector(showButton) withObject:nil afterDelay:1.5];
}
-(IBAction)spin{
BOOL win = NO;
int numInRow = 1;
int lastVal = -1;
for (int i = 0; i < 5; i++)
{
int newValue = random() % [self.column1 count];
if (newValue == lastVal)
numInRow++;
else
numInRow = 1;
lastVal = newValue;
[picker selectRow:newValue inComponent:i animated:YES];
[picker reloadComponent:i];
if (numInRow >= 3)
win = YES;
}
button.hidden = YES;
NSString *path = [[NSBundle mainBundle] pathForResource:@"crunch" ofType:@"wav"];
SystemSoundID soundID;
AudioServicesCreateSystemSoundID((CFURLRef)[NSURL fileURLWithPath:path], &soundID);
AudioServicesPlaySystemSound (soundID);
if (win)
[self performSelector:@selector(playWinSound) withObject:nil afterDelay:.5];
else
[self performSelector:@selector(showButton) withObject:nil afterDelay:.5];
winLabel.text = @"";
}
当您单击旋转按钮时,它会调用此旋转方法。如果获胜为 YES,则调用 playWinSound 将 winLabel 的值更改为 @"Win!"。为什么如果旋转获胜,winLabel 中的文本会变为 @"Win!"并保持这种状态。流程不应该返回到将winLabel更改为@“”的spin方法吗?
【问题讨论】:
标签: iphone objective-c cocoa-touch