apple/iOS, UIKit, Documentation
[iOS] present 이후 pushViewController
lgvv
2022. 8. 5. 16:56
present 이후 pushViewController
그러니까 내가 하고싶은 말은 modal로 띄워진 창에서 pushViewController가 먹히지 않는 상황에 대한 설명이다.
다른 포스팅은 스토리보드를 이용하고 있었고, 난 코드 기반으로 UI를 구성하기에 이에 대한 포스팅을 남겨두고자 함.
상황)
view A, B, C 세가지가 있다고 가정
👉 ViewA
viewA는 SceneDelegate에서 기본적으로 UINavigationController를 Embed in하고 있음.
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
guard let windowScene = (scene as? UIWindowScene) else { return }
window = UIWindow(windowScene: windowScene)
window?.backgroundColor = .systemBackground
window?.rootViewController = UINavigationController(rootViewController: ViewA())
window?.makeKeyAndVisible()
}
✅ 올바르게 작동하는 코드
// 올바르게 작동하는 코드
@objc
func goToViewB() {
let viewController = UINavigationController(rootViewController: ViewB())
viewController.modalPresentationStyle = .fullScreen
self.present(viewController, animated: true)
}
@objc
func goToViewA() {
let viewController = viewB()
self.navigationController?.pushViewController(viewController, animated: true)
}
🚨 잘못 작성한 코드
// 올바르게 작동하는 코드
@objc
func goToViewB() {
let viewController = ViewB()
viewController.modalPresentationStyle = .fullScreen
self.present(viewController, animated: true)
}
@objc
func goToViewC() {
let viewController = ViewC()
self.navigationController?.pushViewController(viewController, animated: true)
}