简体   繁体   中英

how can I set initial viewController that can push after instantiate in swift 5

I can't push from initial viewController after using this code

self.window = UIWindow(frame: UIScreen.main.bounds)

    let storyboard = UIStoryboard(name: "Main", bundle: nil)

    let initialViewController = storyboard.instantiateViewController(withIdentifier: Identifier)

    self.window?.rootViewController = initialViewController
    self.window?.makeKeyAndVisible()

You have to Embed UIViewController in a UINavigationController. Try this one:

let storyboard = UIStoryboard(name: "Main", bundle: nil)

let initialViewController = storyboard.instantiateViewController(withIdentifier: Identifier)

let navController = UINavigationController(rootViewController: initialViewController)

self.window?.rootViewController = navController
self.window?.makeKeyAndVisible()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM