[Swift] ViewController 사이를 전환하는 방법

Oni·2023년 10월 25일
0

기술면접

목록 보기
1/13
post-thumbnail

1. 직접 호출(present)

ViewController를 직접 생성하고 화면에 표시하는 방법

@objc func myPageToReport() {
	let reportVC = ReportViewController()
	reportVC.modalPresentationStyle = .fullScreen
	present(reportVC, animated: true, completion: nil
}   
  • present 방식은 modal 형태로 호출되며, 스타일을 조정할 수 있음
  • fullScreen: 전체 화면을 덮음
  • pageSheet: 부분적으로 덮음
  • formSheet: 작은 폼 시트처럼 화면을 덮음
  • overCurrentContext: 현재 화면 위에 띄우며, 배경을 블러처리 함
  • popover: 작은 팝오버 창에 띄움

2. Navigation Controller

이동할 ViewController를 Navigation Controller 스택에 푸시하여 화면 전환하는 방법

listener.navigationController?.pushViewController(MyPageViewController(), animated: true)

3. Segue

Interface Builder에서 ViewController 간의 화면 전환을 정의한 코드로 해당 segue를 호출하여 전환하는 방법

Segue 정의

  • Storyboard에서 ViewController 간 연결선을 그림
  • Segue에 Identifier를 부여
performSegue(withIdentifier: "SegueIdentifier", sender: self)
profile
하지만 나는 끝까지 살아남을 거야!

0개의 댓글