0
-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
if(actionSheet.tag == 2) {
if(buttonIndex != actionSheet.cancelButtonIndex) {
NSString *s = [actionSheet buttonTitleAtIndex:buttonIndex];
NSString *soundFile = [[NSBundle mainBundle] pathForResource:s ofType:@"m4a"];
NSURL *soundUrl = [NSURL fileURLWithPath:soundFile];
AVAudioPlayer *player = [[AVAudioPlayer alloc]initWithContentsOfURL:soundUrl error:nil];
player.numberOfLoops = 0;
[player play];
}
}
}
중단 점을 [player play];
에 놓고 단계별로 실행하면 iPhone에서 소리가납니다. 브레이크 포인트가 없으면 사운드가 재생되지 않습니다. 왜 이런 일이 일어나는거야?위생 시트 탭에서 소리를 재생하는 데 도움이 필요합니다.
메서드가 범위를 벗어나 자마자 플레이어가 할당 취소 되었기 때문에 (로컬 변수로 만든 이후로) 할당이 취소되었습니다. 플레이어에 대한 강력한 속성을 만들면 제대로 작동합니다. – rdelmar
@rdelmar 답장을 보내 주셔서 감사합니다. 답변을 게시하여 정답으로 투표하고 선택하십시오. –