Swift – Instantiating a navigation controller without storyboards in App Delegate

前端 未结 2 599
余生分开走
余生分开走 2020-12-04 16:48

I\'m rebuilding an app without storyboards and the part of it that I\'m having the most trouble with is navigating view-to-view programatically. Few things are written out t

2条回答
  •  一整个雨季
    2020-12-04 17:31

    In Swift 3

    Place this code inside didFinishLaunchingWithOptions method in AppDelegate class.

    window = UIWindow(frame: UIScreen.main.bounds)
    let mainController = MainViewController() as UIViewController
    let navigationController = UINavigationController(rootViewController: mainController)
    navigationController.navigationBar.isTranslucent = false
    self.window?.rootViewController = navigationController
    self.window?.makeKeyAndVisible()
    

提交回复
热议问题