![](/img/trans.png)
[英]View controller responds to app delegate notifications in iOS 12 but not in iOS 13
[英]iOS 12 / 13 Programmatic View Creation
我的應用程序不使用情節提要。 所有視圖都是以編程方式創建的。
從歷史上看,我已經刪除了我的Main.storyboard
,從我的Info.plist
刪除了引用並設置我的UIWindow
和rootViewController
如下:
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 13 中運行我的應用程序時,我遇到了崩潰 -
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Could not find a storyboard named 'Main' in bundle NSBundle </Users/Dev/Library/Developer/CoreSimulator/Devices/8A4474B1-FCA3-4720-8F34-A6975A03EE19/data/Containers/Bundle/Application/258FA246-A283-4FE6-A075-58BD32424427/Home.app> (loaded)'
***
iOS 12 仍按預期運行。 我應該如何以編程方式設置我的視圖以支持 iOS 12 和 13?
您還需要添加更新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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.