EXC_BAD_ACCESS in the 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.

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.

Hello, buddy!责编内容来自:Hello, buddy! (源链) | 更多关于

阅读提示:酷辣虫无法对本内容的真实性提供任何保证,请自行验证并承担相关的风险与后果!
本站遵循[CC BY-NC-SA 4.0]。如您有版权、意见投诉等问题,请通过eMail联系我们处理。
酷辣虫 » 移动开发 » EXC_BAD_ACCESS in the AppDelegate class declaration

喜欢 (0)or分享给?

专业 x 专注 x 聚合 x 分享 CC BY-NC-SA 4.0

使用声明 | 英豪名录