EXC_BAD_ACCESS when calling pushViewController

I have UITableViewinside a UITabBarController.

When i call

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

no problems.

But, when I call the same line from within UIActionSheetDelegate, for example:

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

I get it EXC_BAD_ACCESS.

It seems that calling this line from another thread is causing this problem.

How can I prevent this problem EXC_BAD_ACCESS?

(note that myViewController is NOT nil or something like that)

thank!

+3
source share
4 answers

EXC_BAD_ACCESS , actionSheet:clickedButtonAtIndex: , , , myViewController.

nil, , . , nil.

+4

, , varible , .

: (myTestViewController )

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

, .

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

. , self.navigationController.delegate = self; .

+1

.

UIActionSheet , : MainRootViewController

myViewController (MainRootViewController).

:

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

myViewController = [[myViewController alloc] init];

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

 }
0

Source: https://habr.com/ru/post/1734891/


All Articles