Objective c iPad VideoPlayerIDFinishPlaying回调方法没有响应

Objective c iPad VideoPlayerIDFinishPlaying回调方法没有响应,objective-c,ipad,Objective C,Ipad,我在ipad视频中遇到了一个问题。我的代码工作得很好,我的意思是它播放视频,但一旦视频结束。不调用回调方法 按下“播放视频”按钮时调用此方法 -(IBAction) playVideo : (id) sender { [self initPlayingVideo:@"toyVid.mp4"]; } 此方法处理视频的播放 -(void) initPlayingVideo: (NSString *) videoFile { NSString *moviePath = [[[NSBundle

我在ipad视频中遇到了一个问题。我的代码工作得很好,我的意思是它播放视频,但一旦视频结束。不调用回调方法

按下“播放视频”按钮时调用此方法

-(IBAction) playVideo : (id) sender
{
  [self initPlayingVideo:@"toyVid.mp4"];
}
此方法处理视频的播放

-(void) initPlayingVideo: (NSString *) videoFile
{
  NSString *moviePath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:videoFile];

  theMovie = [[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL fileURLWithPath:moviePath]];
  theMovie.moviePlayer.scalingMode = MPMovieScalingModeAspectFit;
  theMovie.moviePlayer.controlStyle = MPMovieControlStyleFullscreen;


  [self.view addSubview:theMovie.view];

  [[NSNotificationCenter defaultCenter]
  addObserver:self
  selector:@selector(videoPlayerDidFinishPlaying
  name:MPMoviePlayerPlaybackDidFinishNotification
  object:theMovie];

  videoPlayer = [theMovie moviePlayer];
  [videoPlayer play];
}
这是回调方法

-(void) videoPlayerDidFinishPlaying: (NSNotification*)aNotification
{
  theMovie = [aNotification object];
  [[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification object:theMovie.moviePlayer];
  [videoPlayer stop];
  [theMovie.moviePlayer release];
  [videoPlayer release];
  [theMovie.view removeFromSuperview];
}
我哪里做错了?请导游

问候 Ranjan

您是否错过了选择器中的:和)?我猜)可能是你的打字错误,否则你无法编译你的代码。您的选择包含一个参数。应该是:

selector:@selector(videoPlayerDidFinishPlaying:)

这将与您的实例方法相匹配。我猜你没有一个没有参数。

你可以考虑把你的代码放在代码部分:在代码之前放置四个空格。谢谢你的回复戴维。侦听器函数如下所示。有冒号(:)和右括号“)”。[[NSNotificationCenter defaultCenter]添加观察者:自选择器:@selector(VideoPlayerDifinishPlay:)名称:MPMoviePlayerPlayerPlaybackDidFinishNotification对象:theMovie];