【发布时间】:2019-01-14 04:46:11
【问题描述】:
就我而言,我正在制作一个用于实时聊天的应用程序。我在主视图中使用大标题和搜索栏。但是我想将 tabBar 添加到我的应用程序 navigationController 和 tabBar 不能正常工作。
注意:我用代码做所有事情,请不要告诉我故事板。
应该是这样的:
当我添加 tabBar 时发生了什么:
AppDelegate.swift:
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
UIApplication.shared.statusBarStyle = .lightContent
FirebaseApp.configure()
window = UIWindow(frame: UIScreen.main.bounds)
window?.makeKeyAndVisible()
window?.rootViewController = UINavigationController(rootViewController: TabBarController())
return true
}
TabBarController.swift:
override func viewDidLoad() {
super.viewDidLoad()
let messagesController = UINavigationController(rootViewController: MessagesController())
messagesController.tabBarItem.title = "Sohbetler"
messagesController.tabBarItem.image = UIImage(named: "chats")
viewControllers = [messagesController]
}
【问题讨论】:
-
你需要 TabBarController 的导航控制器吗?您可以删除可以解决问题的 UINavigationController。
-
谢谢,但 chirag 的建议使一切都正确
标签: ios swift tabbar navigationcontroller