var textToPass: String = ""
@IBAction func modalAction(_ sender: Any) {
textToPass = textView.text
print(textToPass)
let storyBoard = UIStoryboard(name: "Main", bundle: nil)
if let secondVC = storyBoard.instantiateViewController(withIdentifier: "SecondVC") as? SecondViewController {
present(secondVC, animated: true, completion: nil)
secondVC.textObject = textToPass // textObject = String?
}
您好。 我不知道为什么secondVC.textObject在这段代码中是nil。 请教我。
答案 0 :(得分:0)
首先为textObject赋值,然后呈现viewController:
if let secondVC = storyBoard.instantiateViewController(withIdentifier: "SecondVC") as? SecondViewController {
secondVC.textObject = textToPass
present(secondVC, animated: true, completion: nil)
}