我对 ios 开发非常陌生,我还不太了解控制台显示的错误。
这是错误:
由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“-[NVViewController Play:]: unrecognized selector sent to instance 0x7a9a2c0”
我把我的代码放在下面,当我触摸播放按钮时会发生错误。
#import "NVViewController.h"
@implementation NVViewController
@synthesize reproductor;
- (void)viewDidLoad
{
[super viewDidLoad];
NSError* error;
NSString* ruta = [[NSBundle mainBundle] pathForResource:@"BackgroundMusic" ofType:@"mp3"];
NSURL* url = [[NSURL alloc] initFileURLWithPath:ruta];
self.reproductor = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:&error];
[self.reproductor prepareToPlay];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)playBackgroundMusic:(id)sender {
[self.reproductor play];
}
- (IBAction)stopBackgroundMusic:(id)sender {
[self.reproductor stop];
}
@end
和标题。
@interface NVViewController : UIViewController
@property (nonatomic,strong) AVAudioPlayer * reproductor;
- (IBAction)playBackgroundMusic:(id)sender;
- (IBAction)stopBackgroundMusic:(id)sender;
@end
谢谢。