2012-06-10 32 views
3

我只是想解僱UIAlertView但我不攻可以用奇怪的錯誤了一些日子...崩潰UIAlertViewDelegate的clickedButtonAtIndex有消息[MPMoviePlayerViewController isKindOfClass:]:消息發送到釋放實例

後的取消按鈕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中顯示

代碼

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

美其名曰,viewDidAppear的調用之後。 有用於enbedding 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

+0

問題不在於UIAlertView,它是在按下取消按鈕後調用的函數。在你的代碼中輸入一個斷點,並檢查崩潰的位置。並告訴我們你在哪裏啓動MPMoviePlayerViewController,在代碼中你是否使用isKinfOfClass方法檢查是否是MPMovieViewController的實例? – doNotCheckMyBlog

+0

謝謝你的回覆。我在我的問題中添加了更多信息。如果您需要更多信息,請寫下來。對此,我真的非常感激。 – Jagie

回答

2

在我看來,你的MPMoviePlayerController實例在viewDidAppear後被釋放。我認爲您應該將vc設置爲View Controller的屬性或實例變量,以便它在View Controller的整個生命週期中保持不變。

+0

非常感謝你!我通過將vc設置爲像@property(strong,nonatomic)MPMoviePlayerViewController * vc這樣的屬性解決了這個問題。 – Jagie

相關問題