我无法将数据从ViewController传递到NewVC - 另一个UIViewController。我一直呆在这里几个小时没有结果,所以这是我解决这个问题的最后手段。执行功能iOS - 无法将数据传递给不同的ViewController
For underlaying idea :
My Code For ViewController
class ViewController: UIViewController{
@IBOutlet weak var name: UITextField!
@IBOutlet weak var lastName: UITextField!
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
switch segue.identifier {
case "seg_One"? :
if let source = segue.source as? ViewController
,let destination = segue.destination as? NewVC {
destination.name.text = source.name.text //Error
destination.lastName.text = source.lastName.text //Error
}
default: break
}
}
// Bunch of other code such as ViewDidLoad()
}
NewVC code:
class NewVC: UIViewController {
@IBOutlet weak var name: UILabel!
@IBOutlet weak var lastName: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
}
}
Error is: fatal error: unexpectedly found nil while unwrapping an Optional value
这是因为当'prepareForSegue()'被调用时'IBOulet'尚未加载并且为零。你必须创建公共字符串属性。 – Larme
https://stackoverflow.com/questions/38357065/unexpectedly-found-nil-iboutlet-in-prepareforsegue https://stackoverflow.com/questions/29239648/prepareforsegue-not-setting-uilabel https://stackoverflow.com/questions/9576177/how-can-i-set-the-value-of-a-uilabel-following-a-segue https://stackoverflow.com/questions/25422536/swift-prepareforsegue-fatal-error-unexpectedly-发现 - 零 - 解包 - 一个 – Larme
谢谢Larme。 :) – Biken