가장 일반적인 화면 전환 방식이다.
예시:
let vc = SecondViewController()
navigationController?.pushViewController(vc, animated: true)
navigationController?.popViewController(animated: true)
NavigationController
└─ FirstViewController
└─ SecondViewController
현재 화면 위에 새로운 화면을 띄우는 방식이다.
예시:
let vc = SecondViewController()
present(vc, animated: true)
dismiss(animated: true)
스토리보드에서 화면끼리 직접 연결하는 방식이다.
performSegue(withIdentifier: "goNext", sender: nil)
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
let nextVC = segue.destination as! SecondViewController
nextVC.name = "홍길동"
}
하단 탭을 눌러 화면을 전환하는 방식이다.
예시:
TabBarController
├─ HomeVC
├─ SearchVC
└─ ProfileVC
보통 아래처럼 조합해서 사용한다.
TabBarController
├─ NavigationController
│ └─ HomeVC
│ └─ DetailVC
└─ NavigationController
└─ SettingVC
즉:
형태로 많이 구성한다.
@IBAction func nextButton(_ sender: UIButton) {
let vc = SecondViewController()
navigationController?.pushViewController(vc, animated: true)
}
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let vc = storyboard.instantiateViewController(
withIdentifier: "SecondViewController"
)
navigationController?.pushViewController(vc, animated: true)
※ Storyboard ID 설정이 필요하다.
방식특징사용 예시
| Push | 스택 구조 | 상세 페이지 |
| Present | 모달 표시 | 로그인, 팝업 |
| Segue | 스토리보드 연결 | 간단한 앱 |
| TabBar | 큰 메뉴 이동 | SNS 앱 |



타입 : UIViewController

바뀐 타입 : DetailViewController

3가지 방법
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
let dest = segue.destination as! DetailViewController
let myIndexPath = table.indexPathForSelectedRow!
let row = myIndexPath.row
print(row)
}
이 코드는 Segue 로 화면 전환이 일어나기 직전에 실행되는 메서드다.
주로 다음 화면에 데이터를 전달할 때 사용한다.
코드 전체를 보면:
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
let dest = segue.destination as! DetailViewController
let myIndexPath = table.indexPathForSelectedRow!
let row = myIndexPath.row
print(row)
}
현재 화면에 UITableView 가 있고,
사용자가 셀을 터치하면:
현재 화면 → DetailViewController
로 이동한다고 가정한 코드다.
override func prepare(for segue: UIStoryboardSegue, sender: Any?)
Segue가 실행되기 직전에 자동 호출되는 메서드다.
즉:
화면 전환 직전
에 실행된다.
let dest = segue.destination as! DetailViewController
이동할 다음 화면(ViewController)을 가져오는 코드다.
즉:
도착할 화면 = DetailViewController
라는 의미다.
let myIndexPath = table.indexPathForSelectedRow!
현재 선택된 테이블 셀의 위치(IndexPath)를 가져온다.
예를 들어:
3번째 셀 클릭
이면:
IndexPath(row: 2, section: 0)
같은 값이 저장된다.
let row = myIndexPath.row
선택된 행 번호만 가져온다.
예:
2
print(row)
선택된 행 번호를 출력한다.
예:
2
출력됨.
보통은 선택한 행 번호를 이용해서
다음 화면에 데이터를 전달한다.
예:
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
let dest = segue.destination as! DetailViewController
let myIndexPath = table.indexPathForSelectedRow!
let row = myIndexPath.row
dest.movieName = movieList[row]
}
테이블 셀 클릭
↓
prepare 실행
↓
몇 번째 셀인지 확인
↓
다음 화면에 데이터 전달
↓
화면 전환
이 코드의 핵심 목적은:
사용자가 선택한 셀 정보를
다음 화면으로 전달하기 위함
이다.

오류 해결 방법





| iOS 프로그래밍실무_11주차_Open API 기반iOS앱 개발(4) (0) | 2026.05.18 |
|---|---|
| iOS 프로그래밍실무_10주차_Open API 기반iOS앱 개발(3) (0) | 2026.05.11 |
| iOS 프로그래밍실무_10주차_Open API 기반iOS앱 개발(3) (0) | 2026.05.11 |
| iOS프로그래밍_9주차_Open API 기반iOS앱 개발(1)RESTful/JSON/Open API (0) | 2026.05.04 |
| 중간고사 (semi-openbook) 안내 (0) | 2026.04.20 |