从 appdelegate 启动 contentview

start contentview from appdelegate

请问您有什么建议吗? 我正在测试一些旧的 pod,我收到“UIAlertView 已弃用且不可用于基于 UIScene 的应用程序,请使用 UIAlertController” 我在某个地方搜索以删除场景委托,注释掉 UISceneSession 等。 我完成了所有步骤,当我启动应用程序时,contentview 始终是黑色的:(

请问如何从appdelegate实例化内容视图?

试试这个:

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool
{   
    let timeline = YourViewController()
    let navigation = UINavigationController(rootViewController: timeline)

    let frame = UIScreen.main.bounds
    window = UIWindow(frame: frame)

    window!.rootViewController = navigation
    window!.makeKeyAndVisible()

    return true
}

SceneDelegate.swift这个不用多说,有几个步骤你要注意。

  • 按照@pkc456 的建议,为您的 AppDelegate window 属性 设置一个 window 实例。
window = UIWindow(frame: UIScreen.main.bounds)
  • 从 AppDelegate 中删除场景配置(您已经通过注释完成了它,如屏幕截图所示)。
  • Info.plist 文件中删除场景配置密钥。

Info.plist > Application Scene Manifest > Scene Configuration

记得使用 View Hierarchy 调试器,有时您会看到正确的视图控制器,但它没有 backgroundColor。

希望对您有所帮助!