在UIAlertViewDelegate的clickedButtonAtIndex消息后发生崩溃[MPMoviePlayerViewController isKindOfClass:]:消息发送到解除分配的实例

时间:2012-06-10 10:21:14

标签: 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

在同一视图中,我嵌入了

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.moviePlayer.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.moviePlayer.view。在其他选项卡的控制器中调用的方法仅为viewWillDisappearviewDidDisappear

1 个答案:

答案 0 :(得分:2)

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