我是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 –