Swift3でsugueを用いた値受け渡し
sugueでFirstViewControllerからSecondViewControllerに値を渡したいのですが
SecondViewControllerでnilになってしまい値が受け取れません
IdentifierはStoryboardで設定済み(sendSecondView)です
###該当のソースコード
FirstSecondViewController.swift(抜粋)
swift
1// SecondViewController操作 2 override func prepare(for segue: UIStoryboardSegue, sender: Any?) { 3 print("send test") 4 if segue.identifier == "sendSecondView" { 5 print("ok") 6 let secondview = segue.destination as! SecondViewController 7 secondview.text1 = "from first" as! String 8 print(secondview.text1) 9 } 10 }
SecondViewController.swift
swift
1class SecondViewController: UIViewController { 2 var text1: String? 3 4 override func viewDidLoad() { 5 super.viewDidLoad() 6 7 print(text1) 8 } 9}
FirstViewControllerのprint(secondview.text1)ではOptional("from first")が表示されるのですが
SecondViewControllerのprint(text1)ではnilになってしまいます
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。