일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
Tags
- button
- PyQt
- Storyboard
- Python
- 개발자
- androidstudio
- UIKit
- PyQt5
- library
- modal
- cocoapods
- 어플리케이션
- Xcode
- Android
- kotlin
- charts
- alamofire
- Chrats
- Swift
- Chart
- TableView
- ios
- 라이브러리
- Apple
- 개발
- ui
- UIButton
- 그래프
- UITableView
- graph
Archives
- Today
- Total
Jiwift
[iOS/Swift] 코드로 UIViewConroller를 UINavigationController로 감싸기 본문
반응형
import UIKit
// MARK: - UINavigationController 생성
static internal func createNavigationController(controller: UIViewController) -> UINavigationController {
// 실제 첫 화면이 되는 ViewController 인스턴스 생성
let childViewController: UIViewController = controller
// NavigationController을 사용할 경우, ViewController를 rootViewController로 갖는 NavigationController을 생성해야한다.
let parentNavigationController: UINavigationController = UINavigationController(rootViewController: childViewController)
// Navigation Controller 반환
return parentNavigationController
}
Stroyboard 없이 코드 베이스 환경에서 사용하는 기준으로 작성되었습니다.
코드를 간단하게 설명하자면, 이동하고 싶은 ViewController가 Present하거나 RootViewController를 통해서 변경되어야하는데 NavigationController의 기능을 사용하고자 할 때 필요합니다.
상위 ViewController가 NavigationController가 아니라면 Push와 같은 동작을 할 수 없기 때문에 구현하고자 하는 기획에 따라서 이러한 작업이 필요할 수 있습니다.
반응형