2011-11-23 39 views
0
使用ARC

我的項目中刪除,所以我不能使用保留,也沒有釋放,在視圖控制器A,I初始化的ViewController B和增加其觀點,作爲一個子視圖:EXC_BAD_ACCESS時從上海華

ViewControllerB *viewB = [[ViewControllerB alloc] init]; 

[self.view addSubview:viewB.view]; 

而且在ViewControllerB,我就這一個按鈕,當用戶點擊,視圖將從上海華盈刪除:

[self.view removeFromSuperview]; 

,結果是EXC_BAD_ACCESS。 請幫助我,並對我的英語感到抱歉。

回答

0

我有同樣的問題太..

嘗試是這樣的:

NSLog("self.view retain count: %d", self.view.retainCount); 
[self.view removeFromSuperview]; 
NSLog("self.view retain count: %d", self.view.retainCount); 

或:

NSLog("self.view.superview retain count: %d", self.view.superview.retainCount); 
[self.view removeFromSuperview]; 
NSLog("self.view.superview retain count: %d", self.view.superview.retainCount); 

這不是很好的做法,但也許你會趕上內存泄漏錯誤... 如果您使用ARC--它不能保護您免於內存管理錯誤...

如果出現錯誤,我很抱歉我的英語。