2017-04-12 18 views
0
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であるのか分かりません。 教えてください。 ViewControllerをtextObjectに、次に提示2つのviewControllersの間で文字列を渡す方法は?

答えて

0

まず割り当て値:

if let secondVC = storyBoard.instantiateViewController(withIdentifier: "SecondVC") as? SecondViewController { 
     secondVC.textObject = textToPass 
     present(secondVC, animated: true, completion: nil) 
} 
関連する問題