"Thread 1: Fatal error: Unexpectedly found nil while unwrapping an Optional value" - 斯威夫特



我正在尝试使用UIViewController显示自定义弹出菜单。 我编写了一个函数来重用显示弹出窗口。 但是,我不断收到上面的错误,我不知道如何处理"nil"。

.SWIFT:

func showPopUp(msg: String){
let storyboard = UIStoryboard.init(name: "Main", bundle: nil)
let popUpVC = storyboard.instantiateViewController(withIdentifier: "popupEmpty") as! PopUpViewController
popUpVC.messageLabel.text = msg  // ""Thread 1: Fatal error: Unexpectedly found nil while unwrapping an Optional value" - SWIFT"
self.present(popUpVC, animated: true, completion: nil) 
}

我的 msg 参数不是选择类型。 我有些困惑。

messageLabelnil直到视图加载(即使正确连接(

class PopUpViewController:UIViewController {
var sendedText = ""
}

然后使用

popUpVC.sendedText = msg  

//

然后将sendedText设置为viewDidLoad内的 LBL

相关内容

最新更新