我有一个应用程序,但使用的是XIB文件,所以如果我在应用程序委托中添加此代码来创建标签栏控制器
let tabBarController = UITabBarController()
let tabViewController1 = DummyViewController(
nibName: "DummyViewController",
bundle: nil)
let tabViewController2 = SearchViewController(
nibName:"SearchViewController",
bundle: nil)
tabViewController1.tabBarItem = UITabBarItem(
title: "Location",
image: UIImage(named: "ic_location_blue"),
tag: 1)
tabViewController2.tabBarItem = UITabBarItem(
title: "Search",
image:UIImage(named: "ic_search_blue") ,
tag:2)
let controllers = [tabViewController1,tabViewController2]
tabBarController.viewControllers = controllers
window?.rootViewController = tabBarController和这段代码创建导航控制器
let viewController = SearchViewController(nibName: nil, bundle: nil)
let navigationController = UINavigationController(rootViewController: viewController)
self.window = UIWindow(frame: UIScreen.main.bounds)
self.window?.rootViewController = navigationController
self.window?.makeKeyAndVisible()它不能,因为我将self.window?.rootViewController = navigationController和window?.rootViewController = tabBarController加在一起。我想要的是这样的:

但在代码中,我需要导航控制器来推送视图控制器。
发布于 2017-01-20 20:59:51
在didFinishLaunchingWithOptions下,编写以下代码:
//创建tab控制器
let tabBarController = UITabBarController()
let tabViewController1 = DummyViewController(
nibName: "DummyViewController",
bundle: nil)
let tabViewController2 = SearchViewController(
nibName:"SearchViewController",
bundle: nil)
tabViewController1.tabBarItem = UITabBarItem(
title: "Location",
image: UIImage(named: "ic_location_blue"),
tag: 1)
tabViewController2.tabBarItem = UITabBarItem(
title: "Search",
image:UIImage(named: "ic_search_blue") ,
tag:2)
let controllers = [tabViewController1,tabViewController2]
tabBarController.viewControllers = controllers
//Create navigation controller
let navigationController = UINavigationController(rootViewController: tabBarController)
self.window = UIWindow(frame: UIScreen.main.bounds)
self.window?.rootViewController = navigationController//Set navigation controller as window's root view
self.window?.makeKeyAndVisible()https://stackoverflow.com/questions/41761199
复制相似问题