-5

这是 Xcode 的错误:

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 play:]:无法识别的选择器发送到实例 0x8a2de20'

*首先抛出调用栈:

(0x1af7012 0x14a4e7e 0x1b824bd 0x1ae6bbc 0x1ae694e 0xeed2c0 0x1ab6376 0x1ab5e06 0x1a9da82 0x1a9cf44 0x1a9ce1b 0x278b7e3 0x278b668 0x3e8ffc 0x28fd 0x2def725 0x1) libc++abi.dylib: terminate called throwing an exception (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];
}
4

1 回答 1

9

有了这个:

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

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

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

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

-(void)play
{
  [self.player play];
}
于 2013-10-25T10:00:11.667 回答