【发布时间】:2020-07-08 11:40:01
【问题描述】:
我的应用程序目标是 iOS 10.0 一旦我更改了目标,我就会在 SceneDelegate 文件中收到一堆错误。为了向后兼容,我为 Scene Delegate 类添加了“@available(iOS 13.0, *)”。
我从 OnboardingController 开始。这完全是程序化的。所以我删除了MainStoryboard,并从info中的“Main Interface”和“Application Scene Manifest”中删除。
现在,我必须在 AppDelegate 和 SceneDelegate 中设置 rootView。如果我没有在 SceneDelegate 中设置窗口,我只会在 iOS 13.0+ 设备中获得黑屏,如果我没有在 AppDelegate 中设置,我只会在 由于我同时调用了这两个文件,因此我在 Viewcontroller 中的 viewdidload() 被调用了两次。
以下是我的 AppDelegate
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
window = UIWindow(frame: UIScreen.main.bounds)
let viewController = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "navC") as! UINavigationController
window?.rootViewController = viewController
window?.makeKeyAndVisible()
return true
}
}
下面是我的 SceneDelegate
@available(iOS 13.0, *)
class SceneDelegate: UIResponder, UIWindowSceneDelegate {
var window: UIWindow?
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
let viewController = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "HomeCollectionVC") as! HomeCollectionVC
window?.rootViewController = viewController
window?.makeKeyAndVisible()
}
...
}
我错过了什么吗?
【问题讨论】:
-
突出显示您的确切问题。
-
是的。你能看看吗谢谢。
-
如你所说如果我没有在 SceneDelegate 中设置窗口你会出现黑屏,但你正在使用 root vc 设置窗口,那么这是什么问题?
-
对不起,我刚刚又编辑了。谢谢你告诉我
标签: ios swift xcode swift3 swift4