IOS-由于未捕获异常而终止应用程序';NSInvalidArgumentException未识别的选择器发送到实例0x7a9a2c0';

IOS-由于未捕获异常而终止应用程序';NSInvalidArgumentException未识别的选择器发送到实例0x7a9a2c0';,ios,audio,Ios,Audio,我对ios开发非常陌生,我还没有真正理解console显示的错误 这就是错误: 由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:'-[NVViewController播放:]:无法识别的选择器发送到实例0x7a9a2c0' 我把我的代码放在下面,当我按下播放按钮时会出现错误 #import "NVViewController.h" @implementation NVViewController @synthesize reproductor;

我对ios开发非常陌生,我还没有真正理解console显示的错误

这就是错误:

由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:'-[NVViewController播放:]:无法识别的选择器发送到实例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

谢谢。

在代码的某个地方(其他地方),您在视图控制器上调用了
Play:
,而不是
playBackgroundMusic:
。错误消息清楚地表明,您将
Play:
发送给了一个
NVViewController
而该控制器不理解该消息。

在代码的某个地方(其他地方),您在视图控制器上调用了
Play:
,而不是
playBackgroundMusic:
。错误消息明确指出,您将
Play:
发送给了一个
NVViewController
,而该控制器不理解该消息。

尝试将self.reproductor=[[AVAudioPlayer alloc]initWithContentsOfURL:url错误:&error];在[自复制器播放]之前播放背景音乐;我建议试试[复制机播放];而不是自我。出于某些原因,您的代码正在NIViewController(self)而不是AVAudioPlayer对象上调用方法。您应该将同样使用self.Replicator的NVViewController中的代码放入,因为您可能正在其他地方将self.Replicator设置为NVViewController对象。请尝试将self.Replicator=[[AVAudioPlayer alloc]initWithContentsOfURL:url错误:&错误];在[自复制器播放]之前播放背景音乐;我建议试试[复制机播放];而不是自我。出于某种原因,您的代码正在调用NIViewController(self)而不是AVAudioPlayer对象上的方法。您应该将同样使用self.Replicator的NVViewController中的代码放入,因为您可能正在其他地方将self.Replicator设置为NVViewController对象。