ios - navigationController 在 Swift 上意外发现 nil

标签 ios swift uiviewcontroller uinavigationcontroller

我遇到了非常奇怪的错误在展开可选值导航 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/

相关文章:

ios - UICollectionView - Swift4 在不同部分的多选和单选

ios - 更新 (15) 后现有部分中包含的行数必须等于

swift - 如何将 UITextField 输入作为整数

ios - 从 xcode 中的另一个 View Controller 禁用按钮

ios - 将 vCard 附加到 MFMessageComposeViewController

ios - CAShapeLayer 没有在 uiview 中正确居中

ios - 体系结构 x86_64 : "_nlist" 的 undefined symbol

ios - 在同一 View Controller 中的多个 View 之间切换

iphone - 更改 UINavigationController 内的 View 高度

ios - 处理程序远程通知背景