1

私はiOS開発に非常に慣れていないため、コンソールに表示されるエラーをまだ理解していません。

これはエラーです:

キャッチされていない例外 'NSInvalidArgumentException' が原因でアプリを終了しています。理由: '-[NVViewController Play:]: 認識されないセレクターがインスタンス 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 に答える