以下代码取自更大的代码,但我相信这是给我带来麻烦的部分。当我运行它时,我没有收到任何错误,但是在按下假设执行的“playMovie”中的硬编码按钮时,“退出电影”我收到消息:由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:'-[ViewController exitMovie :]: unrecognized selector sent to instance 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];
}