I am facing very weird error unexpectedly found nil while unwrapping an optional value navigationcontroller
.
I have two viewControllers which has main function is to scan bar code and sets value in textField on PreBarCodeViewController. Second viewController is the barcodeViewController which scan. According to perspective user either manually input value or scan to fetch bar code. When I go for manual input navigation controller works fine. But once I click for scan and gets value in a textField
and press ok button it won't navigate. Even if I click cross button it gives me nil error.
Updated: included barcode viewcontroller open on button tap.
PreBarcodeViewController: two buttons Back and Accept
@IBAction func toBarcode(_ sender: Any) {
let storyBoard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
let newViewController = storyBoard.instantiateViewController(withIdentifier: "BarcodeViewController") as! BarcodeViewController
present(newViewController, animated: true, completion: nil)
}
@IBAction func onClickedBackArrow(_ sender: Any) {
self.navigationController!.popViewController(animated: true)
}
@IBAction func onClickedAccept(_ sender: Any) {
let value = textField.text ?? String(describing: txtValue)
bardelegate?.listFunc(listValue: value )
self.navigationController?.popViewController(animated: true)
}
BarcodeViewController: When I get the value post to back.
if url == decodedURL {
let storyBoard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
let newViewController = storyBoard.instantiateViewController(withIdentifier: "PreBarcodeViewController") as! PreBarcodeViewController
let str2 = String(url)
newViewController.txtValue = str2
present(newViewController, animated: true, completion: nil)
}