NumberOneRobot
NumberOneRobot

Reputation: 1791

EXC_BAD_ACCESS in AppDelegate class declaration

I've been having issues when segueing in my app with EXC_BAD_ACCESS errors, of code EXC_I386_GPFLT. I've been unable to find much information on this, since there isn't a line of code that I've written that is being pointed to as the culprit. The error is occurring at the line

class AppDelegate: UIResponder, UIApplicationDelegate {

which I didn't even write. I'm not sure how to figure out what is a bad access when nothing I've written is being shown as incorrect.

To put the problem into a bit more perspective,

I have a storyboard that contains a navigation controller, which has a ViewController as its root view controller. The ViewController has a table view that, when a cell is selected, segues to another ViewController. That ViewController may then segue to a third ViewController through a tap gesture segue. This third controller is the navigation controller's delegate, and I set it as that inside the 2nd ViewController's prepareForSegue method,

var dvc = segue.destinationViewController as BlockingViewController
self.navigationController!.delegate = dvc

I ran into this issue when trying to disable the InteractivePopoverGestureRecognizer created automatically by the navigation controller. To do this, I added to the viewDidLoad methods of the 2nd and 3rd ViewControllers the following code:

var barItem: UIBarButtonItem = UIBarButtonItem(title: "Back", style: UIBarButtonItemStyle.Plain, target: self, action: "backButtonPressed")

self.navigationItem.leftBarButtonItem = barItem

and created a backButtonPressed method:

func backButtonPressed() {
    self.navigationController?.popViewControllerAnimated(true)
}

The error occurs when I do the following sequence of actions:

VC1 -> VC2 -> VC3 -> VC2 -> VC1

The error does not occur when I do the following sequence of actions:

VC1 -> VC2 -> VC1

So there must be something happening in VC3 that is causing the issue. The only thing I can think of is that I'm setting it as the navigation controller's delegate, which leads me to wonder if perhaps it's trying to access the delegate during the segue from VC2 -> VC1, which is then causing an error because the delegate is now nil.

Could this be the problem? If not, any insight on what might be the problem would be extremely helpful.

EDIT: I tried the same series of events without setting the navigationController delegate, and didn't have the same issue. The only issue with keeping it like that is that I need the navigationController delegate so I can pass information between VC3 and VC2 when I segue between them.

Upvotes: 2

Views: 1743

Answers (2)

sha
sha

Reputation: 333

I had a similar problem, it was related to a CFString... method call when calling the init method of my custom segue. I fixed the problem by setting am Identifier in the StoryBoard Segue "Attributes Inspector", probably a bug with the xcode version I'm using (6.4).

Upvotes: 0

NumberOneRobot
NumberOneRobot

Reputation: 1791

I found that the problem stopped when I set the navigationController delegate back to nil when I was performing the segue from VC3 back to VC2. I believe the issue was that the delegate property was still referencing VC3, but VC3 no longer existed, so when the navigationController attempted to perform the viewWillAppear method that I'd implemented, the object it was trying to access as delegate no longer existed.

Upvotes: 2

Related Questions