Swift) Navigation Controller를 이용한 값전달
1. 내비게이션컨트롤러를 이용하여 값 전달
- 내비게이션 컨트롤러를 이용한 값전달은 Segue를 이용한 값전달의 기본형태와 유사합니다.
- 화면이동 함수만 푸시방식으로 변경합니다.
1) 소스코드
guard let mainPages = self.storyboard?.instantiateViewController(withIdentifier: "mainPage")
as? MainViewController else {
return
}
mainPages.name2 = "sion"
let nC = UINavigationController(rootViewController: mainPages)
nC.modalTransitionStyle = .coverVertical
self.navigationController?.pushViewController(mainPages, animated: true)
2. 화면 복귀 시에 값 전달
1) 소스코드
@IBAction func goBack(_ sender: Any) {
print("\(self.navigationController?.accessibilityElementCount())")
guard let vc = self.navigationController?.viewControllers[0] as? ViewController else{
return
}
vc.retName = "return Success"
self.navigationController?.popViewController(animated: true)
}
|