gpt4 book ai didi

ios - Swift - 带 TabBar 的 NavigationBar 不能正常工作

转载 作者:行者123 更新时间:2023-11-28 05:54:54 25 4
gpt4 key购买 nike

就我而言,我正在制作一个用于实时聊天的应用程序。我在主视图中使用大标题和搜索栏。但是,我想将 tabBar 添加到我的应用程序 navigationController 中,但 tabBar 无法正常工作。

注意:我正在用代码做所有事情,请不要告诉我 Storyboard。

这是应该的:

enter image description here

当我添加 tabBar 时发生了什么:

enter image description here

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]
}

最佳答案

你把两个导航一个用于标签栏,第二个用于 Controller 隐藏一个导航栏,你的问题就会解决

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {

UIApplication.shared.statusBarStyle = .lightContent

FirebaseApp.configure()
window = UIWindow(frame: UIScreen.main.bounds)
window?.makeKeyAndVisible()
let objNav = UINavigationController(rootViewController: TabBarController())
objNav.isNavigationBarHidden = true
window?.rootViewController = objNav

return true
}

关于ios - Swift - 带 TabBar 的 NavigationBar 不能正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51720934/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com