我在 didFinishLaunchingWithOptions 中有这段代码:
window = UIWindow(frame: UIScreen.mainScreen().bounds)
let tabBarController = UITabBarController()
let listTableViewController = ListTableViewController()
listTableViewController.tabBarItem = UITabBarItem(tabBarSystemItem: .Contacts, tag: 0)
var navViewController = UINavigationController(rootViewController: listTableViewController)
tabBarController.viewControllers?.append(navViewController)
let galleryViewController = GalleryViewController()
galleryViewController.tabBarItem = UITabBarItem(tabBarSystemItem: .Featured, tag: 1)
navViewController = UINavigationController(rootViewController: galleryViewController)
tabBarController.viewControllers?.append(navViewController)
let serviceViewController = ServiceViewController()
serviceViewController.tabBarItem = UITabBarItem(tabBarSystemItem: .More, tag: 2)
navViewController = UINavigationController(rootViewController: serviceViewController)
tabBarController.viewControllers?.append(navViewController)
tabBarController.selectedIndex = 0
window?.rootViewController = tabBarController
window?.makeKeyAndVisible()
return true
但是,当应用程序启动并且徽标消失时,我只有黑屏并且标签栏上没有标签,但我想至少看到ListTablevViewController中的空表视图。
答案 0 :(得分:2)
我下载了你的项目,似乎viewControllers的附加功能无法正常工作,因为tabBarController.viewControllers在某种程度上是零。我做了这个小测试,效果很好:
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
window = UIWindow(frame: UIScreen.mainScreen().bounds)
let tabBarController = UITabBarController()
let listTableViewController = ListTableViewController()
listTableViewController.tabBarItem = UITabBarItem(tabBarSystemItem: .Contacts, tag: 0)
let navViewController = UINavigationController(rootViewController: listTableViewController)
tabBarController.viewControllers?.append(navViewController)
let galleryViewController = GalleryViewController()
galleryViewController.tabBarItem = UITabBarItem(tabBarSystemItem: .Featured, tag: 1)
let navViewController1 = UINavigationController(rootViewController: galleryViewController)
tabBarController.viewControllers?.append(navViewController)
let serviceViewController = ServiceViewController()
serviceViewController.tabBarItem = UITabBarItem(tabBarSystemItem: .More, tag: 2)
let navViewController2 = UINavigationController(rootViewController: serviceViewController)
tabBarController.viewControllers?.append(navViewController)
let controllers = [navViewController, navViewController1, navViewController2]
tabBarController.selectedIndex = 0
tabBarController.viewControllers = controllers
window!.rootViewController = tabBarController
window!.makeKeyAndVisible()
return true
}