这是代码
let storyBoard = UIStoryboard(name: "Main", bundle: nil)
let vc = storyBoard.instantiateViewController(withIdentifier: "homeTBC") as! UITabBarController
self.window?.rootViewController = vc
self.window?.makeKeyAndVisible()
无法想象它。
答案 0 :(得分:2)
来自Apple的Documentation
创建窗口时,始终设置窗口的初始大小和 指定显示它的屏幕。
添加尺寸:
self.window = UIWindow.init(frame: UIScreen.main.bounds)
您的完整代码应该是这样的:
let storyBoard = UIStoryboard(name: "Main", bundle: nil)
let vc = storyBoard.instantiateViewController(withIdentifier: "homeTBC") as! UITabBarController
self.window = UIWindow.init(frame: UIScreen.main.bounds)
self.window?.rootViewController = vc
self.window?.makeKeyAndVisible()
答案 1 :(得分:2)
我已经在My App中尝试了这个代码,用于在app delegate中完成根视图控制器:
由于我认为您在呈现的视图控制器或呈现的导航控制器中使用此代码:请发送方案(屏幕截图)确切地说您正在做什么?
var window: UIWindow?
window = UIWindow(frame: UIScreen.main.bounds)
window?.makeKeyAndVisible()
let storyBoard = UIStoryboard(name: "Main", bundle: nil)
let vc = storyBoard.instantiateViewController(withIdentifier: "TabbarVC") as! TabbarVC
self.window?.rootViewController = vc