2010-03-01 30 views
3

我在UITabBarController內有UITableViewEXC_BAD_ACCESS在調用pushViewController時

當我打電話

[[self navigationController] pushViewController:myViewController animated:YES]; 

是沒有問題的。

但是,當我打電話從UIActionSheetDelegate內的同一行,例如:

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex 

我得到EXC_BAD_ACCESS

似乎是從另一個線程調用此行導致此問題。

如何防止EXC_BAD_ACCESS問題?

(注意myViewController不是零,或類似的東西)

的感謝!當您試圖訪問一個釋放的對象

+1

你可以請你發佈actionSheet的所有代碼:clickedButtonAtIndex,這樣我們可以更好地幫助你解決你的問題嗎? – Convolution 2010-03-01 15:39:20

+0

當你有這個錯誤時,你是否打開了debbuger(gdb)來關注哪個是導致這個錯誤的指令?你可以在這裏發佈這個細節嗎? – 2010-03-01 16:44:27

+0

調用: [[self navigationController] pushViewController:myViewController animated:YES]; 導致錯誤 – taxman 2010-03-02 12:39:23

回答

4

EXC_BAD_ACCESS被拋出,並actionSheet:clickedButtonAtIndex:被稱爲主線程上,動作片被駁回後,所以我猜什麼用myViewController指出被釋放。

它並不一定是nil,事實上,這就是問題所在。指出的對象被釋放,但指針不是nil

+0

tnx。 UIActionSheet從名爲MainRootViewController的類中調用: myViewController是此類中的成員。 完整的代碼是: - (無效)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger的)buttonIndex { \t myViewController = [[myViewController的alloc] INIT]; \t [[self navigationController] pushViewController:myViewController animated:YES]; \t } – taxman 2010-03-01 15:54:47

+0

你能看到爲什麼我有這個EXC_BAD_ACCESS錯誤嗎? – taxman 2010-03-01 16:32:36

0

tnx。

的UIActionSheet從被呼叫類中調用:MainRootViewController

myViewController是在這個類(MainRootViewController)的成員。

完整的代碼是:

-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex { 

myViewController = [[myViewController alloc] init]; 

[[self navigationController] pushViewController:myViewController animated:YES]; 

} 
+0

你確定這是你的真實代碼嗎?因爲你在指針上調用alloc,而不是類。 – 2010-03-01 19:39:53

+0

不,我的錯。該行是: myViewController = [[MyViewController alloc] init]; – taxman 2010-03-02 11:25:03

1

我只是有同樣的問題,我的是,我沒有assine自成員varible當我alloced它。

這causeed一個問題:(myTestViewController是類成員)

TestViewController* test = [[TestViewController alloc] init]; 
    myTestViewController = testViewController; 
    [testViewController release]; 
     [[self navigationController] pushViewController:myTestViewController animated:YES]; 

但是,當我改變與自我assied類的成員,它的工作。

TestViewController* test = [[TestViewController alloc] init]; 
    self.myTestViewController = testViewController; 
    [testViewController release]; 
     [[self navigationController] pushViewController:myTestViewController animated:YES]; 
1

我有類似的問題。我修復它的方法是從我的推送視圖控制器中刪除self.navigationController.delegate = self;

相關問題