0

,當我通過解僱ModalViewController我的應用程序崩潰:請協助modalViewController崩潰

[self.parentViewController dismissModalViewControllerAnimated:YES]; 

這種模式視圖 - 控制器(「MVC」)提出,當用戶點擊一個UINavigationController的細胞之一(「NavRoot」) - 這裏是對於該代碼:

MVC *modalView = [[MVC alloc] initWithNibName:@"MVC" bundle:nil]; 
[self.navigationController presentModalViewController: modalView animated:YES]; 
[modalView release];   

其被加載的「modalView」只包含2個對象:一個UIWebView對象和「完成」按鈕,這點擊的何時的dissmissing通過:

[self.parentViewController dismissModalViewControllerAnimated:YES]; 

除了當我點擊「完成」 - 應用程序崩潰。

當我使用NSZombies運行儀器時,我發現保留計數達到-1,但我無法確定是什麼原因導致了這種過度釋放。

我發現的唯一的事情解決了問題是,要麼添加了「[modalView保留]」聲明「NavRoot」 - 這是對的viewController做modalView的呈現:

MVC *modalView = [[MVC alloc] initWithNibName:@"MVC" bundle:nil]; 
[self.navigationController presentModalViewController: modalView animated:YES]; 
[modalView retain]; // <<== new 'retain' statement 
[modalView release]; 

或者只是簡單地從來沒有釋放modalView擺在首位:

MVC *modalView = [[MVC alloc] initWithNibName:@"MVC" bundle:nil]; 
[self.navigationController presentModalViewController: modalView animated:YES]; 
// commenting out the 'release': 
// [modalView release]; 

這兩個選項扔國旗當我運行「分析」(「上線34分配的對象的潛在泄漏」 ......),但他們這樣做解決問題。 不過,我擔心這會導致應用程序被Apple從App Store拒絕。

關於可能導致過度釋放的任何想法?或者我可能會進一步嘗試隔離/識別問題?

連接儀器的圖像/殭屍報告: enter image description here

+0

你可以顯示殭屍儀器的歷史嗎? –

+0

好吧,我會放棄它 - 現在運行,但一定會發布它,因爲我絕對需要到這個底部! – sirab333

+0

你的MVC dealloc是什麼樣的? MVC是否充當webview的委託,如果是的話,你是否在dealloc中進行清理? –

回答

1

你使用iOS 5嗎?我有同樣的問題,當我打開一個應用程序從iOS4的到5

ParentViewController現在被稱爲presentingViewController

什麼可以做,雖然是在你的模式的看法只是調用[自我dismissModalViewController],它應該解僱自己。我不是100%的,不能檢查,因爲我不是我的Mac附近,但我記得在文檔中閱讀它,

+0

我正在使用iOS 4.0。 2和「presentsViewController」僅僅是iOS 5,所以我不能使用它。至於使用普通老式[self dismissModalViewCOntroller] - 這就是我從一開始就這樣做的事情 - 而且它在實際物理方面工作得很好迪打開modalViewController - 但應用程序崩潰。我研究並找到了使用「[self.ParentViewController dismissModalViewController]」的建議 - 這也起作用,但也導致崩潰。所以無論我使用什麼樣的「自我」變體,應用程序都會崩潰。但它不是那個。它關於保留/釋放問題(續) – sirab333

+0

看來我正在釋放 - 或試圖與之交談 - 不再存在的viewController。它已經被髮布了。但我無法弄清楚它釋放了什麼。有任何想法嗎? – sirab333

+0

我曾經遇到過web請求的問題,因爲它們是異步的,如果我設置了webrequest,然後解散了我的模式視圖控制器,webrequest試圖調用我的viewcontroller中的一個方法,該方法現在正在發佈。我的問題是,我沒有清除我的委託在Web請求。所以我會在模態視圖控制器中檢查你的dealloc方法,並確保你的代表在webview上設置爲零,並取消webview上的任何請求。我之前沒有使用過webview,所以不知道你需要檢查什麼,但那是我看的第一個地方。 –

0

如果你

[self.navigationController presentModalViewController: modalView animated:YES];

那麼你應該關閉它像

[self.navigationController dismissModalViewControllerAnimated:YES];

而不是

[self.parentViewController dismissModalViewControllerAnimated:YES];

你在哪裏試圖解除視圖?實際的modalView或父視圖?在我看來,你試圖駁回已經被解僱並隨後被釋放的模態觀點。

+0

我解散了modalView,在modalView裏有一個「DONE」按鈕,當點擊它時,調用「[self.parentViewController dismissModalViewControllerAnimated:YES];」聲明。嘗試將其切換到「[self.navigationController dismissModalViewControllerAnimated:YES];」 - 現在它什麼都不做,它根本不釋放modalView,它只是坐在那裏... – sirab333

0

要關閉modalViewController我只是做:[self dismissModalViewControllerAnimated:YES];

0

[self dismissModalViewControllerAnimated:YES]在iOS 5

我建立了一個類iOS上4.添加presentingViewController(它禁用本身在iOS 5)

只包含2個文件,和它的作品完美不起作用。請參閱backward-modal

我希望這對你有利,就像它對我有利;它使你的代碼更加乾淨!