make a class variable for the audioPlayer:
AVAudioPlayer *cellTapSound;
in viewDidLoad (or viewWillAppear):
cellTapSound = [[AVAudioPlayer alloc] initWithContentsOfURL:[[NSBundle mainBundle] URLForResource:@"cellTapSound" withExtension:@"mp3"] error:nil];
[cellTapSound prepareToPlay];
in 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];
do not forget to:
- add AVFoundation.framework to your project
#import <AVFoundation/AVFoundation.h>
- Drag&Drop audio file into your project bundle and update the URL for AVAudioPlayer init
- read about AVAudioPlayer to find out what else you can do with it