The following code is taken from much larger code but I believe that this is the section that is giving me trouble. when I run it I get no errors but upon pressing the hardcoded button inside 'playMovie' that is suppose to execute, 'exit movie' I get the message: Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[ViewController exitMovie:]: unrecognized selector sent to instance 0x7a4b350' I've done some research on this and found reasons why it does this but I can't seem to make sense of my case. I am a novice coder however so I am probably just missing something. Hope this is enough to solve the problem, if not I can send more code.
-(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];
}
It looks like you are trying to execute the wrong method; exitMovie:
(note the colon) is not the same as exitMovie
. Perhaps the method should be defined as:
- (IBAction)exitMove:(id)sender
{
...
}
Which does match the exitMovie:
selector.