iphone - UIAlertViewDelegate 的 clickedButtonAtIndex 后崩溃并显示消息 [MPMoviePlayerViewController isKindOfClass :]: message sent to deallocated instance

标签 iphone ios xcode mpmovieplayercontroller uialertview

我只是想关闭 UIAlertView 但我不能因为一个奇怪的错误几天...

点击UIAlertView上的取消按钮后,下面的代码可以工作。

- (void) alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex 
{
    [alertView dismissWithClickedButtonIndex:buttonIndex animated:YES];
}

但是通过这些行后,它会导致崩溃并显示以下消息:

[MPMoviePlayerViewController isKindOfClass:]: message sent to deallocated instance 0x27f590

在同一 View 上,我嵌入

MPMoviePlayerViewController.moviePlayer.view
[self.view addSubview:vc.moviePlayer.view];

有人知道发生了什么事吗? 我用的是ARC,iOS5.1。如果您需要更多信息,我会添加它们。

提前谢谢您。

更多信息:

我在代码中的所有方法上设置了断点。 我确保它在 clickedButtonAtIndex 之后崩溃...

调用UIAlertView show的代码为

-(void)applicationDidBecomeActive:(NSNotification *)notification
{
    self.alert = hoge; // set delegate = self
    [self.alert show];
}

调用它们之后,viewDidAppear被调用。 有一些用于嵌入 vc.movi​​ePlayer.view 的代码,例如

MPMoviePlayerViewController *vc;
vc = [[MPMoviePlayerViewController alloc] initWithContentURL:hogeURL];

[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(finishPreload:)
                                             name:MPMediaPlaybackIsPreparedToPlayDidChangeNotification
                                           object:vc];

[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(finishPlayback:)
                                             name:MPMoviePlayerPlaybackDidFinishNotification
                                           object:vc];

vc.view.frame = CGRectMake( 0, 0, 320, 440);

vc.moviePlayer.allowsAirPlay = YES;
vc.moviePlayer.shouldAutoplay = NO;
vc.moviePlayer.controlStyle = MPMovieControlStyleEmbedded;
vc.moviePlayer.useApplicationAudioSession = NO;

[vc.moviePlayer.view setTag:310];

[self.view addSubview:vc.moviePlayer.view];

我的应用有 3 个选项卡,其中 2 个嵌入了 MPMoviePlayerViewController.movi​​ePlayer.view。其他选项卡 Controller 中调用的方法仅限于 viewWillDisappearviewDidDisappear

最佳答案

在我看来,您的 MPMoviePlayerController 实例在 viewDidAppear 之后被释放。我认为您应该将 vc 设置为 View Controller 的属性或实例变量,以便它在 View Controller 的整个生命周期中持续存在。

关于iphone - UIAlertViewDelegate 的 clickedButtonAtIndex 后崩溃并显示消息 [MPMoviePlayerViewController isKindOfClass :]: message sent to deallocated instance,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10967912/

相关文章:

ios - 如何在 iOS 中的 PDF 文件中绘制表格。

iphone - 在另一个 View 中呈现 modalViewController

iphone - 警告 : passing argument 1 of 'setOn:' makes integer from pointer without a cast

ios - 无法打开文件 "<appName>.app",因为您没有查看它的权限

ios - 带 wifi 的外部附件

iphone - 如何在 iPhone 上制作包含数据表的 PDF 文档?

iphone - iOS 7 是否提供了为 VoiceOver 设置捆绑显示名称 plist 值的方法?

ios - 将更多项目添加到 ScrollView 顶部时,将现有项目向下移动

swift - 如何使用 swift 引用文本字段?

iphone - 在 hittest 中的点上应用 CGAffineTransformRotate