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

时间:2013-02-16 06:55:09

标签: ios audio

我对ios开发很新,我还没有真正了解控制台显示的错误。

这是错误:

由于未捕获的异常'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

感谢。

1 个答案:

答案 0 :(得分:1)

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