我遇到了非常奇怪的错误在展开可选值导航 Controller 时意外发现nil
。
我有两个viewController,其主要功能是扫描条形码并在PreBarCodeViewController 上的textField 中设置值。第二个viewController是扫描的barcodeViewController。根据用户的需要,可以手动输入值或扫描获取条形码。当我进行手动输入时,导航 Controller 工作正常。但是,一旦我单击扫描并在 textField
中获取值并按“确定”按钮,它就不会导航。即使我单击十字按钮,它也不会给我任何错误。
更新:包含的条形码 View Controller 在按钮点击时打开。
PreBarcodeViewController:两个按钮“返回”和“接受”
@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:当我返回值时。
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)
}
最佳答案
当您使用 present()
View Controller 打开时,然后使用
解雇()
返回上一屏幕的方法。
popViewController()
仅在您使用导航 Controller 导航时使用,请检查此项。
关于ios - navigationController 在 Swift 上意外发现 nil,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59155762/