去除Storyboard,改用纯代码
Xcode: Version 13.0 (13A233)
Swift: Version 5.5
创建新的项目后,项目默认使用的是Storyboard,现在想改用纯代码的方式
1.删除 Main Interface
路径: TARGETS -> General
将 Main Interface 中的值删除

2.删除 Storyboard Name
路径:Info -> Scene Configuration -> Application Session Role -> Storyboard Name

删除 Storyboard Name 这一项(点击减号删除)

3.代码创建根控制器
路径:SceneDelegate

在 SceneDelegate 中的
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions)
编写代码创建方式
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
guard let _ = (scene as? UIWindowScene) else { return }
guard let windowSence = (scene as? UIWindowScene) else { return }
window = UIWindow(frame: windowSence.coordinateSpace.bounds)
window?.windowScene = windowSence
let navigationController = UINavigationController(rootViewController: NewsViewController())
navigationController.navigationBar.prefersLargeTitles = true
window?.rootViewController = navigationController
window?.makeKeyAndVisible()
}

浙公网安备 33010602011771号