Swift 转发数据时有趣的 NSExceptionError

Swift Interesting NSExceptionError When Passing Data Forward

我这里有一个非常简单的问题,我无法解决。这段代码工作得很好,将我带到了第五个视图控制器。

@objc func OnbtnPlusTouched()

{
    let uivc = storyboard!.instantiateViewController(withIdentifier: "FifthViewController")
    navigationController!.pushViewController(uivc, animated: true)

}

但是,我想将这个 viewcontroller 的数据 locationName 传递给下一个。因此我使用了这个代码段:

@objc func OnbtnPlusTouched()

{
    let vc = FifthViewController(nibName: "FifthViewController", bundle: nil)
    vc.locationName = locationName
    navigationController?.pushViewController(vc, animated: true)
}

但现在我在我的应用程序中输入此功能后立即收到此错误:

libc++abi.dylib: terminating with uncaught exception of type

NSException and Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Could not load NIB in bundle: 'NSBundle

非常感谢任何帮助,谢谢!

试试这个

@objc func OnbtnPlusTouched() {
    guard let uivc = storyboard!.instantiateViewController(withIdentifier: "FifthViewController") as? FifthViewController else {
         return 
    }
    uivc.locationName = locationName
    navigationController!.pushViewController(uivc, animated: true)
}