2011-10-14 52 views
-1

我在導航控制器上推送一個對象,但是當我從該視圖控制器返回控件時,它會使應用程序崩潰。當瀏覽控制器從導航控制器彈出時,應用程序崩潰

[self.navigationController pushViewController:chequeDetails animated:YES]; 
     [chequeDetails release]; 

,但是當我寫與

[self.navigationController pushViewController:chequeDetails animated:YES]; 
chequeDetails=nil; 
[chequeDetails release]; 

該應用程序相同的代碼不會崩潰,但略有滯後觀察......當我從彈出的檢查細節控制器回來?

回答

0

如果你秒的exaple代碼,你沒有釋放chequeDetails因爲nil對象上調用release沒有什麼:

[self.navigationController pushViewController:chequeDetails animated:YES]; 
chequeDetails=nil; 
// calling the release on nill will do nothing 
[chequeDetails release]; 

通常情況下,你可以做這種方式:

[self.navigationController pushViewController:chequeDetails animated:YES]; 
[chequeDetails release], chequeDetails = nil; 

但只有釋放chequeDetails如果你做了一個分配,像這樣的init:

ChequeDetails *chequeDetails = [[ChequeDetails alloc] initWithNibName:@"ChequeDetails" bundle:nil]; 

所以完整的代碼應該是這樣的:

ChequeDetails *chequeDetails = [[ChequeDetails alloc] initWithNibName:@"ChequeDetails" bundle:nil]; 
[self.navigationController pushViewController:chequeDetails animated:YES]; 
[chequeDetails release], chequeDetails = nil; 
-1

我不知道Exat ...但我認爲你需要創建委託的對象,你需要寫appDelegate.navigationController而不是self.navigationController ...

注:的appDelegate是的對象代表。

相關問題