我这里有一个非常简单的问题,我无法解决。这段代码运行良好,将我带到了第五个视图控制器。
@objc func OnbtnPlusTouched()
{
let uivc = storyboard!.instantiateViewController(withIdentifier: "FifthViewController")
navigationController!.pushViewController(uivc, animated: true)
}
但是,我想将数据locationName从此viewcontroller传递给下一个。因此,我使用了以下代码段:
@objc func OnbtnPlusTouched()
{
let vc = FifthViewController(nibName: "FifthViewController", bundle: nil)
vc.locationName = locationName
navigationController?.pushViewController(vc, animated: true)
}
但是现在我在应用程序中输入以下功能后就收到了此错误:
libc ++ abi.dylib:以类型未捕获的异常终止
由于未捕获的异常,NSException和终止应用程序
“ NSInternalInconsistencyException”,原因:“无法在其中加载NIB
捆绑包:'NSBundle
我将不胜感激,谢谢!
最佳答案
试试这个
@objc func OnbtnPlusTouched() {
guard let uivc = storyboard!.instantiateViewController(withIdentifier: "FifthViewController") as? FifthViewController else {
return
}
uivc.locationName = locationName
navigationController!.pushViewController(uivc, animated: true)
}