我的应用程序不使用情节提要。所有视图都是以编程方式创建的。
从历史上看,我删除了title
,从Main.storyboard
中删除了引用,并按如下所示设置了Info.plist
和UIWindow
:
rootViewController
但是,当尝试在iOS 13中运行我的应用程序时,出现崩溃-
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
let window = UIWindow(frame: UIScreen.main.bounds)
window.rootViewController = UIViewController()
window.makeKeyAndVisible()
self.window = window
return true
}
iOS 12仍按预期运行。如何以编程方式设置视图以支持iOS 12和13?
答案 0 :(得分:1)
您还需要添加更新SceneDelegate.swift
。
更新func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions)
并添加
guard let windowScene = (scene as? UIWindowScene) else { return }
let window = UIWindow(windowScene: windowScene)
let viewController = ViewController()
window.rootViewController = viewController
window.makeKeyAndVisible()
self.window = window