当用户点击一个单元格时我想要它播放声音时我想要做什么。到目前为止,从我搜索的内容来看,它必须在以下方面实施:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[self.tableView deselectRowAtIndexPath:indexPath animated:NO];
}
我只是不知道最好的称呼方式。任何帮助,将不胜感激。
为 audioPlayer 创建一个类变量:
AVAudioPlayer *cellTapSound;
在 viewDidLoad(或 viewWillAppear)中:
cellTapSound = [[AVAudioPlayer alloc] initWithContentsOfURL:[[NSBundle mainBundle] URLForResource:@"cellTapSound" withExtension:@"mp3"] error:nil];
[cellTapSound prepareToPlay];
在 didSelectRowAtIndexPath 中:
// this line will rewind the player each time you tap again before it ends playing
// you can tap as fast as you can and play some sort of a tune
// must have some fun while testing
if (cellTapSound.isPlaying) [cellTapSound setCurrentTime:0.0];
[cellTapSound play];
不要忘记:
#import <AVFoundation/AVFoundation.h>