나는 Beginning iPhone Development을 통해 작업하고 있습니다. 이 방법은 다음과 같습니다.Objective-C의 제어 흐름
-(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 = @"";
}
스핀 단추를 클릭하면이 스핀 방식이 호출됩니다. win이 YES이면 winLabel의 값을 @ "Win!"으로 변경하는 playWinSound가 호출됩니다. 스핀 결과가 승리하면 winLabel의 텍스트가 @ "Win!"으로 변경됩니다. 그런 식으로 남는다. 흐름이 winLabel을 @ ""로 바꿀 스핀 방식으로 돌아 가지 않아야합니까?