应用程序崩溃,发送到实例的无法识别的选择器

时间:2013-10-25 09:57:26

标签: ios iphone objective-c

这是Xcode shoy my:

的错误
  

2013-10-25 11:43:35.059 ChineseCheckers [7220:c07] - [HomeViewController   play:]:无法识别的选择器发送到实例0x8a2de20 2013-10-25   11:43:35.062 ChineseCheckers [7220:c07] * 终止应用程序   未捕获的异常'NSInvalidArgumentException',原因:   ' - [HomeViewController播放:]:无法识别的选择器发送到实例   0x8a2de20'

* 第一次抛出调用堆栈:

  

(0x1af7012 0x14a4e7e 0x1b824bd 0x1ae6bbc 0x1ae694e 0xeed2c0 0x1ab6376   0x1ab5e06 0x1a9da82 0x1a9cf44 0x1a9ce1b 0x278b7e3 0x278b668 0x3e8ffc   0x28fd 0x2def725 0x1)libc ++ abi.dylib:终止调用throw a   异常(lldb)0x8a2de20

我正在设法为我的应用添加背景音,我把源代码

-(IBAction)play
{
    NSString *soundFilePath =[[NSBundle mainBundle] pathForResource: @"larga"ofType: @"mp3"];
    NSURL *fileURL = [[NSURL alloc] initFileURLWithPath: soundFilePath];
    AVAudioPlayer *newPlayer =[[AVAudioPlayer alloc] initWithContentsOfURL: fileURL error: Nil];

    self.player = newPlayer;

    [self.player prepareToPlay];
    [self.player setDelegate: self];
    [self.player play];
    [NSTimer scheduledTimerWithTimeInterval: 30 target: self
                                   selector: @selector(play:) userInfo: nil repeats: YES];
}

    - (void)viewDidLoad
{
    [super viewDidLoad];
    .............................
    ...............................

        [self.player play];
}

1 个答案:

答案 0 :(得分:9)

有了这个:

[NSTimer scheduledTimerWithTimeInterval: 30 target: self
                               selector: @selector(play:) userInfo: nil repeats: YES];

您正在视图控制器上调用方法播放,该方法不存在。

尝试创建它(删除:from play:在选择器中):

[NSTimer scheduledTimerWithTimeInterval: 30 target: self
                               selector: @selector(play) userInfo: nil repeats: YES];

-(void)play
{
  [self.player play];
}