Search code examples
iosxcodeswiftuiwebviewexc-bad-access

EXC_BAD_ACCESS when performing a segue to ViewController with a UIWebView?


So I have a setup like this:

enter image description here

Where I have a custom code reader view controller, and as soon as it detects a barcode, I want it to segue to another view controller with a label and a UIWebView. So far, it works perfectly with just the label being displayed. For some reason, all I did was add a UIWebView and added an IBOutlet in my Second View Controller custom class and the segue won't work due to the exc_bad_access error. The error highlights the following line in my code reader view controller:

self.performSegueWithIdentifier("push", sender: self) //my segue is named push

Here is my second view controller code:

import UIKit

public class SecondViewController: UIViewController {
    var setText:String!
    @IBOutlet weak var WebV: UIWebView!


    @IBOutlet var label: UILabel!
    override public func viewDidLoad() {
        label.text = setText
    }

}

SOLUTION: So I just realized that, for some reason, my segue was running off the main thread. Does this happen in a closure? And, does this mean that you can't perform a segue in a closure/block?

Any help is greatly appreciated. Thank you so much.


Solution

  • So I just realized that, for some reason, my segue was not running on the main thread. Dispatching to the main queue fixed the issue.