2010-03-01 7 views
3

UITabBarController 안에 UITableView이 있습니다.pushViewController를 호출 할 때 EXC_BAD_ACCESS

나는 아무 문제가 없다

[[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

+0

이 오류가 발생하면 debbuger (gdb)를 열어서이 오류의 원인이되는 명령을 집중 시켰습니까? 여기에 자세한 내용을 게시 할 수 있습니까? –

+0

전화 : [[자가 navigationController] pushViewController : myViewController animated : YES]; 오류가 발생했습니다. – taxman

답변

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 [[자체 navigationController] pushViewController : myViewController animated : YES]; \t } – taxman

+0

내가 왜이 EXC_BAD_ACCESS 오류가 있는지 확인할 수 있습니까? – taxman

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을 호출하기 때문입니다. –

+0

아니요, 저의 실수입니다. 라인은 다음과 같습니다 : myViewController = [[MyViewController alloc] init]; – taxman

1

난 그냥 같은 문제를했고 광산은 내가 alloced 때 자기와 멤버 varible을 assine하지 않았다이었다.

문제가 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;을 제거하는 것이 었습니다.

관련 문제