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正在播放的聲音。沒有斷點就不會播放聲音。爲什麼發生這種情況?需要幫助的uiactionsheet自來水
因爲只要方法超出範圍,您的播放器就會被釋放(因爲您將其作爲局部變量創建)。爲玩家創造一個強大的財產,它會正常工作。 – rdelmar
@rdelmar感謝您的回覆,請將其發佈爲答案,以便我可以投票並選擇正確的答案。 –