Jaume
Jaume

Reputation: 3790

EXC_BAD_ACCESS when popViewController

I am pushing BViewController from A properly. B contains a webview that starts loading a page when viewDidLoad. I am getting a strange behavior when popping B to A,

  1. If webview finishes its load and then I execute popViewController (IBAction when touchUpInside on a toolbar button), popped to A so everything works perfectly.
  2. However, if I popViewController immediately before webview ends its load, app crashes due to exc_bad_access. why? view is already loaded!

I checked on both situations viewcontrollers that are on navigation stack. Both cases with same result, 2 same objects, no difference!

-(IBAction)goBackOrg:(id)sender{

    NSArray *viewControllers = self.navigationController.viewControllers;

    [[self navigationController]  popViewControllerAnimated:NO];

}

and for previously pushing it, I am using

if(!self.BController){

            self.BController = [[BViewController alloc] initWithNibName:@"BViewController" bundle:nil anUrlDest:urlSocial];
        }

    [[self navigationController] pushViewController:self.BController animated:NO];

Upvotes: 2

Views: 1673

Answers (2)

Rajneesh071
Rajneesh071

Reputation: 31091

May be You are loading your webView on Thread and when you are using thread then you cannot do changes in UI otherwise your app will crash.

So just do this task on mainThread .

Upvotes: 0

occulus
occulus

Reputation: 17014

EXC_BAD_ACCESS occurs when you're trying to access an object that has been deallocated.

So the following could be your problem: when you pop ViewController B, it is being unloaded. If the web view loading finishes after ViewController B is unloaded, some piece of callback code is getting executed that is trying to do something with your ViewController or its view (or similar).

Upvotes: 1

Related Questions