我是Swift和iOS开发的新手。我目前有2 ViewControllers
,第一个button
和第二个label
。我已将第一个button
连接到第二个ViewController
,并且转换工作正常。单击第一个ViewController中的按钮更改第二个ViewController的标签文本
现在,当我尝试改变标签的文本,我得到的错误:
fatal error: unexpectedly found nil while unwrapping an Optional value
。
这里你可以找到我的第一ViewController
准备功能:
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "mySegue" {
let vc = segue.destination as! SecondViewController
vc.secondResultLabel.text = "Testing"
}
}
它可以是在第二ViewController
标签以某种方式保护?
感谢您的帮助
看起来类似:http://stackoverflow.com/questions/39887587/error-found-nil-while-unwrapping-an-optional-value-while-pass-data-to-the-new/39887622#39887622 –