I am building an iOS app in swift and upon launching the app I would like to first show viewController2, which is presented on top of viewController1, which is embedded in a UINavigationController. The key part being that ViewController2 is not part of the navigation stack and is presented instead of being pushed.
This is my current attempt which doesn't work and only shows ViewController1 upon launch.
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
let mainStoryboard = UIStoryboard(name: "Main", bundle: nil)
let viewController1 = mainStoryboard.instantiateViewController(withIdentifier: "VC1") as! ViewController1
let viewController2 = mainStoryboard.instantiateViewController(withIdentifier: "VC2") as! ViewController2
let navController = UINavigationController(rootViewController: viewController1)
viewController1.present(viewController2, animated: false)
self.window?.rootViewController = navController
self.window?.makeKeyAndVisible()
return true
}
I have this structure in place because I enable a user to be able to swipe from left to right and right to left to get to viewController2 and viewController3 in a similar fashion to Snapchat. Presenting these controllers seemed the best idea as they don't have navigation bars and once finished you would want to return to viewControlller1 - perhaps I need to change the structure of my app but would ideally not like to as I aim to submit this mvp within the next week.
Help much appreciated from you iOS and swift wizards.
// Think I need to change the structure of the app to include viewController2 on the navigation stack :( as using accepted answer causes viewController1 to be seen briefly before viewController2 is presented which is logical - in the long run this will be better despite the short term pain