let firstVC = FirstViewController()
self.present(firstVC, animated: true, completion: nil)
guard let secondVC = storyboard?.instantiateViewController(withIdentifier: "secondVC") as? SecondViewController else { return }
//secondVC.someString = "안녕하세요"
//secondVC.mainLabel.text = "안녕하세요" // 에러발생 (스토리보드 객체가 나중에 생김)
//secondVC.modalPresentationStyle = .fullScreen
self.present(secondVC, animated: true, completion: nil)
// 세그웨이를 실행한다는 의미의 메서드 호출
self.performSegue(withIdentifier: "toThirdVC", sender: self)
// 데이터 전달을 위해 prepare를 재정의
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
//print(#function)
if segue.identifier == "toThirdVC" {
let thirdVC = segue.destination as! ThirdViewController
thirdVC.someString = "안녕하세요"
//thirdVC.mainLabel.text = "안녕하세요" // 에러발생 (스토리보드 객체가 나중에 생김)
// 참고 - 4) 직접 세그웨이에서만 호출되는 메서드 : 뷰가 아닌 버튼으로 직접적으로 연결했을 경우만 가능
// 조건에 따라 다음화면 이동할지/말지
override func shouldPerformSegue(withIdentifier identifier: String, sender: Any?) -> Bool {
print(#function)
if identifier == "toFourthVC" {
return false
}
return true
}
2번 방법이 제일 좋다.