我对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
谢谢。
最佳答案
在代码中的某个地方(其他地方),您在 View Controller 上调用了Play:
而不是playBackgroundMusic:
。该错误消息清楚地表明,您将Play:
发送到了一个不理解该消息的NVViewController
。
关于ios - iOS-由于未捕获的异常 'NSInvalidArgumentException unrecognized selector sent to instance 0x7a9a2c0'而终止应用程序,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/14907828/