创建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() } }

内容的提问来源于stack exchange,提问作者sdweh
相关产品推荐
相关产品推荐

