class FirstViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
}
@IBAction func changeLabel(_ sender: UIButton) {
guard let vc = storyboard?.instantiateViewController(identifier: "SecondViewController")
as? SecondViewController else { return }
vc.text = "data Passing" // 보내는 데이터
navigationController?.pushViewController(vc, animated: true) // 보냄
}
}
class SecondViewController: UIViewController {
var text: String = ""
@IBOutlet weak var passingInfo: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
}
@IBAction func changeLabel(_ sender: UIButton) {
passingInfo?.text = text
}
}
그림과 같이 identifier를 설정하지 않아 오류가 났었다.
Class 이외에도 Storyboard ID를 같게 설정해 주어야 연결이 되는 것을 알게 되었다.
오래 앉아 있어서 그런지 기력이 떨어져 비타민을 먹기로 했다.
몸 챙겨 먹고 살자.