Unknown Hush
Unknown Hush

Reputation: 1

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()

Upvotes: 0

Views: 94

Answers (1)

MBT
MBT

Reputation: 1391

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()

Upvotes: 1

Related Questions