How do I create a new Swift project without using Storyboards?

后端 未结 13 956
不知归路
不知归路 2020-11-29 15:47

Creating a new project in XCode 6 doesn\'t allow to disable Storyboards. You can only select Swift or Objective-C and to use or not Core Data.

I tried deleting the s

13条回答
  •  生来不讨喜
    2020-11-29 16:13

    In iOS 13 and above when you create new project without storyboard use below steps:

    1. Create project using Xcode 11 or above

    2. Delete storyboard nib and class

    3. Add new new file with xib

    4. Need to set root view as UINavigationController SceneDelegate

    5. add below code 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 _ = (scene as? UIWindowScene) else { return }

      if let windowScene = scene as? UIWindowScene { self.window = UIWindow(windowScene: windowScene) let mainController = HomeViewController() as HomeViewController let navigationController = UINavigationController(rootViewController: mainController) self.window!.rootViewController = navigationController self.window!.makeKeyAndVisible() } }

提交回复
热议问题