views:

430

answers:

2

Hi

I have a UITableView inside a UITabBarController.

When I'm calling

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

there is no problem.

but,

When I'm calling the same line from inside a UIActionSheetDelegate, for example:

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

I get EXC_BAD_ACCESS.

It seems that calling this line from a different thread causing this issue.

How can I prevent this EXC_BAD_ACCESS issue?

(notice that myViewController is NOT nil, or something like that)

thanks!

+1  A: 

EXC_BAD_ACCESS is thrown when you try to access a released object, and actionSheet:clickedButtonAtIndex: is called on the main thread, after the action sheet is dismissed, so I'm guessing what's pointed by myViewController is released.

It doesn't have to be nil, in fact, that's the problem. The object pointed is released, but the pointer is not nil.

Can Berk Güder
tnx.The UIActionSheet is called from within a class called: MainRootViewControllermyViewController is a member in this class.The full code is:- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{ myViewController = [[myViewController alloc] init]; [[self navigationController] pushViewController:myViewController animated:YES]; }
taxman
can you see why i have this EXC_BAD_ACCESS error?
taxman
A: 

tnx.

The UIActionSheet is called from within a class called: MainRootViewController

myViewController is a member in this class (MainRootViewController).

The full code is:

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

myViewController = [[myViewController alloc] init];

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

 }
taxman
are you sure this is your real code? because you're calling alloc on a pointer, not a class.
Can Berk Güder
no, my mistake. the line is:myViewController = [[MyViewController alloc] init];
taxman