以下代码来自更大的代码,但我相信这是给我带来麻烦的部分。当我运行它时,我没有错误,但是按下'playMovie'里面的硬编码按钮,假设要执行,'退出电影'我收到消息:由于未捕获的异常'NSInvalidArgumentException'终止应用程序,原因:' - [ViewController exitMovie :]:无法识别的选择器发送到实例0x7a4b350'我已经对此做了一些研究,并找到了解决这个问题的原因,但我似乎无法理解我的情况。我是一个新手编码器,所以我可能只是错过了一些东西。希望这足以解决问题,如果不是我可以发送更多代码。
-(IBAction)playMovie{
UIButton *buttonPress = [UIButton buttonWithType:UIButtonTypeCustom];
[buttonPress addTarget:self
action:@selector(exitMovie:)
forControlEvents:UIControlEventTouchUpInside];
buttonPress.frame = CGRectMake(0.0, 0.0, 1000.0, 1000.0);
buttonPress.backgroundColor = [UIColor clearColor];
[self.view addSubview:buttonPress];
NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle]pathForResource:@"We_Cant_Elope" ofType:@"mov"]];
MPMoviePlayerController *playerViewController = [[MPMoviePlayerController alloc] init];
playerViewController.contentURL = url;
playerViewController.view.frame = CGRectMake(120,300, 550, 400);
[self.view addSubview:playerViewController.view];
[playerViewController play];
self.playerViewController = playerViewController;
}
-(IBAction)exitMovie{
[self.playerViewController.view removeFromSuperview];
[self.playerViewController stop];
}
答案 0 :(得分:0)
看起来你正试图执行错误的方法; exitMovie:
(请注意冒号) 与exitMovie
相同。也许该方法应定义为:
- (IBAction)exitMove:(id)sender
{
...
}
哪个匹配exitMovie:
选择器。