How to launch new project without a storyboard >= iOS 13 in Xcode 11?

纵然是瞬间 提交于 2020-03-25 22:36:36

问题


Xcode 11 with iOS 13 now launches with a slightly different setup from before, moving many functions from the AppDelegate.m file into a new file called SceneDelegate.m - deleting the Main.storyboard and setting the root view controller in AppDelegate is no longer an option, leading to the error below:

-[AppDelegate window]: unrecognized selector sent to instance

How to continue building new projects without storyboard?


回答1:


Check this post: Xcode 11.3 | Remove Storyboard from project

Step 1: Delete Storyboard

After successfully creation new project, navigate to Project Navigator found in left corner of the Xcode window. We need to delete Main.storyboard file from here.

Step 2: Remove Main Interface

Then move to General Tab and delete your Main Interface link here and hit enter.

Step 3: Delete Storyboard file from Info.plist.

Remove Main.storyboard from Info.plist. enter image description here

Step 4: Make your app run without Storyboard.

If you have seen carefully in Project Navigator you can see 2 delegate files AppDelegate.swift and SceneDelegate.swift. So in previous Xcode’s we have seen there was UIWindow variable present in AppDelegate.swift and now for Xcode 11 it’s gone. Now you can see window variable in SceneDelegate.swift file. In this file you need to make configuration for you load you xib file.

func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
    guard let windowScene = (scene as? UIWindowScene) else { return }
    window = UIWindow(frame: windowScene.coordinateSpace.bounds)
    window?.windowScene = windowScene
    window?.rootViewController = ViewController()
    window?.makeKeyAndVisible()
}

🤘That’s it! Now you can run your App without Storyboard.

GitHub sample project




回答2:


Answer is already in question: you need add window property. Xcode 11 doesn't generate it.




回答3:


You could still use this empty application template in Xcode 11.



来源:https://stackoverflow.com/questions/58655903/how-to-launch-new-project-without-a-storyboard-ios-13-in-xcode-11

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!