Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/36.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
iphone ios xcode 4.2-EXC\u坏访问信号_Iphone_Ios_Xcode_Ios5 - Fatal编程技术网

iphone ios xcode 4.2-EXC\u坏访问信号

iphone ios xcode 4.2-EXC\u坏访问信号,iphone,ios,xcode,ios5,Iphone,Ios,Xcode,Ios5,我正在设计一款iPhone应用程序,可以在本地播放视频。当我点击模拟器中的按钮时,它可以完美地播放,但当它停止或当我手动结束时,它崩溃并不断地给我这个问题。。我试着再次清洁、建造、分析和运行,但仍然是一样的。有什么帮助吗 我的代码是: movieplayervewcontroller.h #import <UIKit/UIKit.h> #import <Foundation/Foundation.h> #import <MediaPlayer/MediaPlayer

我正在设计一款iPhone应用程序,可以在本地播放视频。当我点击模拟器中的按钮时,它可以完美地播放,但当它停止或当我手动结束时,它崩溃并不断地给我这个问题。。我试着再次清洁、建造、分析和运行,但仍然是一样的。有什么帮助吗

我的代码是:

movieplayervewcontroller.h

#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#import <MediaPlayer/MediaPlayer.h>

@interface MoviePlayerViewController : UIViewController {

}
-(IBAction)playMovie:(id)sender;
@end

代码中几乎没有问题,以下是修复程序:

1> 移除
[mpviewController释放][通知对象]
)。要释放
mpviewController
对象,请将其声明为实例变量,然后释放并使其为零

if(mpviewController != nil) 
{  
[mpviewController release];  
mpviewController = nil;
}
2> 由于您已将
mpviewController
声明为实例变量,因此无需通过
[notification object]
访问
mpviewController
变量,因为它不在那里,因为您在将observer添加到通知中心时没有提供它

3> 替换以下代码行:

 [[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification object:mpviewController];

说明:添加观察者时,您没有提供任何对象信息,但在删除时,您需要

因此,现在您的代码将变成:

- (void)playbackFinishedCallback:(NSNotification *)notification {

    [[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification object:nil];
    [mpviewController.view removeFromSuperview];
   if(mpviewController != nil)
    {
        [mpviewController release];
        mpviewController = nil;
     }
}
此外,在该控制器的
-(void)dealoc
中,您应该编写类似的代码来释放
mpviewController


谢谢,

你试过制作电影播放器控制器吗

  #import <UIKit/UIKit.h>
  #import <Foundation/Foundation.h>
  #import <MediaPlayer/MediaPlayer.h>

  @interface MoviePlayerViewController : UIViewController {

  }

  @property (nonatomic, retain) MPMoviePlayerViewController *mpviewController;

  -(IBAction)playMovie:(id)sender;
  @end

使用僵尸工具运行你的应用程序。它会准确地告诉你问题出在哪里,怎么解决?在新的xcode中是完全不同的。我搜索了它,但还没有找到。如果你进入你的方案设置,会有一个僵尸勾选框。这将导致您尝试访问的僵尸对象打印在日志中。然后您可以看到它们是什么并修复它们:)或者您可以从Xcode中的“产品”菜单中选择“配置文件”,然后当Instruments打开时,选择Zombies instrument。确保您正在构建模拟器,因为设备上没有僵尸仪器。当应用程序出现错误时,您将在Instruments(仪器)窗口中看到一个弹出的小框,如果您单击框中的箭头,您可以获得有关导致错误的对象的信息。我尝试过,但它无法识别mpviewController。。我声明它没有错误,但它仍然不断崩溃,并给我相同的错误。。
- (void)playbackFinishedCallback:(NSNotification *)notification {

    [[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification object:nil];
    [mpviewController.view removeFromSuperview];
   if(mpviewController != nil)
    {
        [mpviewController release];
        mpviewController = nil;
     }
}
  #import <UIKit/UIKit.h>
  #import <Foundation/Foundation.h>
  #import <MediaPlayer/MediaPlayer.h>

  @interface MoviePlayerViewController : UIViewController {

  }

  @property (nonatomic, retain) MPMoviePlayerViewController *mpviewController;

  -(IBAction)playMovie:(id)sender;
  @end
  @synthesize mpviewController;

  - (IBAction)playMovie:(id)sender {
      NSString *movpath = [[NSBundle mainBundle] pathForResource:@"think" ofType:@"mp4"];
      MPMoviePlayerViewController *mpController = [[MPMoviePlayerViewController alloc]
                                                       initWithContentURL:[NSURL fileURLWithPath:movpath]];

      self.mpviewController = mpController; 
      [mpController release];                                              

      [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(playbackFinishedCallback:)
                                                   name:MPMoviePlayerPlaybackDidFinishNotification object:nil];

      [self.view addSubview:self.mpviewController.view];
      MPMoviePlayerController *mp = [self.mpviewController moviePlayer];
      [mp prepareToPlay];
      mp.scalingMode=MPMovieScalingModeAspectFill;
      [[self.mpviewController moviePlayer] play];
  }

  - (void)playbackFinishedCallback:(NSNotification *)notification {

      [[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification object:mpviewController];
      [mpviewController.view removeFromSuperview];
  }

  - (void)viewDidUnload {
    self.mpviewController = nil;
  }

  - (void)dealloc{
    self.mpviewController = nil;

    [super dealloc];
  }