我面临一个很奇怪的问题,我的要求是发挥按钮单击声音,这是我的代码:播放声音单击
- (void)viewDidLoad
{
[super viewDidLoad];
NSString *path=[[NSBundle mainBundle] pathForResource:@"button-3" ofType:@"mp3"];
tapSound=[[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL]];
[tapSound prepareToPlay];
tapSound.delegate=self;
//creating the button in view did load and button is declared in .h
btn=[UIButton buttonWithType:UIButtonTypeCustom];
btn.frame=CGRectMake(x, y, 58,58);
[btn addTarget:self action:@selector(btnClkd:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:btn];
}
//click method
-(void)btnClkd:(UIButton*)sender
{
[tapSound play];
}
但是当我运行的代码,然后点击按钮我的应用程序得到坠毁,得到这个错误:“终止应用程序由于未捕获的异常‘NSInvalidArgumentException’,原因是:‘ - [UIButton的发挥]:无法识别的选择发送到实例0x758c790’”
但是如果我播放声音的任何地方否则,但不是在按钮的点击,然后它没有任何问题发挥。我不知道为什么会发生这种情况?请帮我
通过分配它来尝试按钮。 我不确定,但只是试试这样。 – Deepak