【问题标题】:Swift - NavigationBar with TabBar not working wellSwift - 带有 TabBar 的 NavigationBar 无法正常工作
【发布时间】: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


【解决方案1】:

在您想要显示标签栏的视图控制器中尝试以下行

self.tabBarController?.tabBar.isHidden = false

【讨论】:

    【解决方案2】:

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

    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
    }
    

    【讨论】:

    • 等待时限,我会的:)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-11-13
    • 2018-11-03
    • 2020-05-17
    • 2017-11-25
    • 2018-08-29
    • 2019-12-03
    相关资源
    最近更新 更多