2010-08-16 50 views
0

爲了加速我的應用程序,我在AppDelegate中創建了三個不同的UIViewController,並且它具有控制器的只讀屬性。這些控制器用於導航控制器。當調用[UINavigationController pushViewController]時獲取'EXC_BAD_ACCESS'信號

如果我點擊根視圖上的按鈕,我只是使用pushViewController方法顯示另一個視圖。讓我在此向您展示一些代碼。

UIViewController* controller = delegate.anotherViewController; 
[delegate.navigationController pushViewController:controller animated:YES]; 

,第一時間,這項工作做得很好,但如果我導航回來,再次點擊按鈕,我得在第二線的信號「EXC_BAD_ACCESS」。

怎麼了?而且,如何在開始時準備所有視圖控制器,而不是在需要時創建它們?

回答

0

大多數情況下,EXC_BAD_ACCESS意味着你已經發布了一個對象,並且你試圖在不保留它的情況下重用它。 看看你是否已經釋放你的viewController太早,並且你是否(重新)以正確的方式使用它...

0

我有同樣的問題。我的代碼是

AddMedia *info = [[AddMedia alloc] initWithStyle:UITableViewStyleGrouped]; 
[self.navigationController pushViewController:info animated:YES]; 
[info release]; 

我正在釋放我的viewCOntroller是崩潰的應用程序。

當我評論該行時,它可以無縫工作。更改後的代碼是:

AddMedia *info = [[AddMedia alloc] initWithStyle:UITableViewStyleGrouped]; 
[self.navigationController pushViewController:info animated:YES]; 
// [info release]; 
相關問題