I have an app which has a tableview. when certain cells are selected a new view controller with a xib is loaded. The xib has a UIButton which when selected plays an audio file. The audio file played depends on which cell is selected and is designated in a plist associated with the tableview. I have created an NSString properties for the audio file and I have "didSelectRowAtIndexPath" assigning these properties. Then in the view controller I have tried to set up the audio in the ViewDidLoad but for some reason it is not working. Can someone help me out?
here is some of my code
this is in my table view.
- (void)tableView

UITableView *)tableView didSelectRowAtIndexPath

NSIndexPath *)indexPath {
const NSDictionary *const row = [self rowForIndexPath:indexPath];
NSString *wantedClassName = [row objectForKey:@"controller"];
UIViewController *const vc = [[NSClassFromString (wantedClassName) alloc] init];
NSLog(@"controller is -%@-", wantedClassName);
if ([vc isKindOfClass:[Location_One class]])
{
Location_One* loVC = (Location_One*)vc;
loVC.myAudio = [row objectForKey:@"audio"];
}
Viewcontroller .h file
#import <UIKit/UIKit.h>
#import <AVFoundation/AVAudioPlayer.h>
@interface Location_One : UIViewController <AVAudioPlayerDelegate> {
AVAudioPlayer *theAudio;
NSString *myAudio;
}
@property (nonatomic, retain) NSString *myAudio;
@property (nonatomic, retain) AVAudioPlayer *theAudio;
-(IBAction)pushButton;
-(IBAction)play;
-(IBAction)stop;
-(IBAction)pause;
@end
viewcontroller .m file
@synthesize myAudio;
@synthesize theAudio;
-(IBAction)pushButton {
}
-(IBAction)play {
[theAudio play];
}
-(IBAction)stop {
[theAudio stop];
}
-(IBAction)pause {
[theAudio pause];
}
- (void)viewDidLoad {
[super viewDidLoad];
NSString *audioFilePath = [[NSBundle mainBundle] pathForResource:self.myAudio ofType:@"mp3"];
if (theAudio) [theAudio release];
theAudio = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL URLWithString:audioFilePath] error:nil];
theAudio.delegate =self;
[theAudio play];
}
I have assigned the button in IB.