[英]I am not able to access tabbarcontroller from appdelegate in swift ios
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
self.window?.backgroundColor = UIColor.white
self.window?.makeKeyAndVisible()
let tabBarController = UITabBarController()
let myVC1 = ViewController(nibName: "ViewController", bundle: nil)
let myVC2 = ViewController1(nibName: "ViewController1", bundle: nil)
let controllers = [myVC1,myVC2]
tabBarController.viewControllers = controllers
window?.rootViewController = tabBarController
let firstImage = UIImage(named: "Search")
let secondImage = UIImage(named: "Search1")
myVC1.tabBarItem = UITabBarItem(
title: "Pie",
image: firstImage,
tag: 1)
myVC2.tabBarItem = UITabBarItem(
title: "Pizza",
image: secondImage,
tag:2)
// Override point for customization after application launch.
return true
A black screen appears whenever I run the app. 每当我运行应用程序时,都会出现黑屏。
I think you did not pervoid UIWindow size window = UIWindow(frame: UIScreen.main.bounds) window?.rootViewController = UITabBarController() 我认为您没有避免UIWindow大小window = UIWindow(frame:UIScreen.main.bounds)window?.rootViewController = UITabBarController()
or you some problem with setting root view controller. 或者您在设置根视图控制器时遇到问题。
You need to add window = UIWindow at the beginning of app Delegate didFinishLaunchingWithOptions: or else there isn't a frame size set. 您需要在应用程序的开头添加window = UIWindow委托didFinishLaunchingWithOptions:,否则未设置框架大小。 Thats why your getting the black screen.
那就是为什么您得到黑屏。
window = UIWindow(frame: UIScreen.main.bounds)
self.window?.backgroundColor = UIColor.white
let tabBarController = UITabBarController()
let myVC1 = UIViewController()
let myVC2 = UIViewController()
let controllers = [myVC1,myVC2]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.