You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

创建UINavigationController或UITabBarController时出现空白屏,求排查方案

编程方式添加UINavigationController和UITabBarController后显示空白屏问题排查

尝试以编程方式在应用首页添加UINavigationController和UITabBarController,已尝试多种方法仍无法解决。代码先后放在SceneDelegate和AppDelegate文件中均无效果,严格按照教程编写代码后,运行模拟器仅显示空白屏,与教程效果不符。以下是当前SceneDelegate中的代码,恳请帮忙排查是否有遗漏要点:

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 }
        // ViewController1()  ViewController2()
        let mainView = UINavigationController(rootViewController: ViewController())
        let VC1 = UINavigationController(rootViewController: ViewController1())
        let VC2 = UINavigationController(rootViewController: ViewController2())
        let tab = UITabBarController()
        tab.viewControllers = [VC1, VC2, mainView]
        window = UIWindow(frame: UIScreen.main.bounds)
        window?.windowScene = windowScene
        window?.rootViewController = tab
        window?.makeKeyAndVisible()
    }
}

iPhone 12 Pro模拟器空白屏截图

内容的提问来源于stack exchange,提问作者sdweh

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.20 15:48:11