我只是想关闭 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.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
。其他选项卡 Controller 中调用的方法仅限于 viewWillDisappear
和 viewDidDisappear
。
最佳答案
在我看来,您的 MPMoviePlayerController
实例在 viewDidAppear
之后被释放。我认为您应该将 vc 设置为 View Controller 的属性或实例变量,以便它在 View Controller 的整个生命周期中持续存在。
关于iphone - UIAlertViewDelegate 的 clickedButtonAtIndex 后崩溃并显示消息 [MPMoviePlayerViewController isKindOfClass :]: message sent to deallocated instance,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10967912/