How to use UINavigationController programmatically
1. Make ios project no storyboard setting.
Here is my link to set no storyboard.
https://antwhale94.blogspot.com/2023/07/howtosetnostoryboard.html
2. Set UINavigationController to start window's rootViewController
import UIKit
class SceneDelegate: UIResponder, UIWindowSceneDelegate {
var window: UIWindow?
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
// Use this method to optionally configure and attach the UIWindow `window` to the provided UIWindowScene `scene`.
// If using a storyboard, the `window` property will automatically be initialized and attached to the scene.
// This delegate does not imply the connecting scene or session are new (see `application:configurationForConnectingSceneSession` instead).
guard let windowScene = (scene as? UIWindowScene) else { return }
window = UIWindow(windowScene: windowScene)
let rootVC = ViewController()
let navVC = UINavigationController(rootViewController: rootVC)
window?.rootViewController = navVC
window?.makeKeyAndVisible()
}
}
댓글 없음:
댓글 쓰기