1

我对 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

谢谢。

4

1 回答 1

1

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

于 2013-02-16T07:22:17.750 回答