【问题标题】:start contentview from appdelegate从 appdelegate 启动 contentview
【发布时间】:2021-04-20 21:36:57
【问题描述】:

请问,您能给点建议吗? 我正在测试一些旧 pod,但我收到“UIAlertView 已弃用,并且对于基于 UIScene 的应用程序不可用,请使用 UIAlertController” 我在某处搜索以删除场景委托、注释掉 UISceneSession 等。 我做了所有的步骤,当我启动应用程序时,内容视图总是黑色的:(

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

【问题讨论】:

  • 窗口将为零;你需要创建一个实例
  • @Paulw11 确切地说:D 抱歉我错过了创建实例

标签: ios swift swiftui appdelegate


【解决方案1】:

试试这个:

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
}

【讨论】:

    【解决方案2】:

    SceneDelegate.swift 不必评论,有一些步骤您必须注意。

    • 按照@pkc456 的建议,为您的 AppDelegate window 属性设置一个窗口实例。
    window = UIWindow(frame: UIScreen.main.bounds)
    
    • 从 AppDelegate 中删除场景配置(您已经按照屏幕截图所示对其进行了评论)。
    • Info.plist 文件中删除场景配置密钥。

    Info.plist > Application Scene Manifest > Scene Configuration

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

    希望我能帮上忙!

    【讨论】:

    • 感谢创建 UIWindow 实例的人 :) 我觉得自己很愚蠢
    猜你喜欢
    • 2014-11-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-11-22
    • 1970-01-01
    • 1970-01-01
    • 2012-08-11
    相关资源
    最近更新 更多