我是Swift和iOS开发的新手。我目前有2个ViewControllers,button第一个是a label,第二个是a。我已经将第一个连接button到第二个ViewController,并且过渡工作正常。
现在,当我尝试更改标签的文本时,出现错误:
致命错误:解开Optional值时意外发现nil
。
在这里,您可以在第一个地方找到我的prepare函数ViewController:
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "mySegue" {
let vc = segue.destination as! SecondViewController
vc.secondResultLabel.text = "Testing"
}
}
Run Code Online (Sandbox Code Playgroud)
可以ViewController保护第二个标签吗?
谢谢您的帮助