[Swift] 화면 간 이동

Dzeko·2021년 9월 6일

Swift 기본

목록 보기
19/20
post-thumbnail

push - pop 방식

push

@IBAction func btnPushWithCode(_ sender: Any) {
    guard let viewController = self.storyboard?.instantiateViewController(identifier: "PushWithCodeViewController") else { return }
    self.navigationController?.pushViewController(viewController, animated: true)
}

pop

@IBAction func btnBack(_ sender: UIButton) {
    self.navigationController?.popViewController(animated: true)
}

View Controller에서 다른 View Controller를 호출하여 전환

present - dismiss 방식

present

@IBAction func btnPresentWithCode(_ sender: Any) {
    guard let viewController = self.storyboard?.instantiateViewController(identifier: "PresentWithCodeViewController") else { return } // PresentWithCodeViewController 라는 identifier를 가진 화면을 불러올거야
    viewController.modalPresentationStyle = .fullScreen // present 방식에 대한…
    self.present(viewController, animated: true, completion: nil) // completion 뒤의 closure 문이 실행됨
}

dismiss

@IBAction func btnBack(_ sender: UIButton) {
    self.presentingViewController?.dismiss(animated: true, completion: nil)  // completion 뒤의 closure 문이 실행됨
}

0개의 댓글