【问题标题】:How can I get rid of the 2nd navigation bar? They are directly on top of one another如何摆脱第二个导航栏?它们直接在彼此之上
【发布时间】:2020-05-24 23:45:04
【问题描述】:

点击链接查看图片

导航栏上方有一些东西,我对它是什么以及如何摆脱它感到困惑。

这是我的 tabController 代码

    {import UIKit
class TabBarController: UITabBarController, UITabBarControllerDelegate {
    override func viewDidLoad() {
        delegate = self
        authenticateUserAndConfigureView()
    }
    func setupViewControllers() {
        let home = templateNavController(viewController: DiscoverViewController(), image: UIImage(named: "house")!, title: "Home")
        let search = templateNavController(viewController: SearchViewController(), image: UIImage(named: "search")!, title: "Discover")
        let problem = templateNavController(viewController: NewProblemViewController(), image: UIImage(named:"addproblem")!, title: "Add New Problem")
        let chat = templateNavController(viewController: MessageViewController(), image: UIImage(named: "chat")!, title: "Chat")
        let profile = templateNavController(viewController: ProfileViewController(), image: UIImage(named: "profile")!, title: "Profile")
        self.viewControllers = [home, search, problem, chat, profile]
    }
    func authenticateUserAndConfigureView() {

        DispatchQueue.main.async {
            if Auth.auth().currentUser == nil {
                let navController = UINavigationController(rootViewController: LoggedOut())
                navController.modalPresentationStyle = .fullScreen
                self.present(navController, animated: true, completion: nil)
            } else {
                self.setupViewControllers()
            }
        }
    }
    func templateNavController(viewController:  UIViewController,  image: UIImage, title: String)  ->  UINavigationController {
        let navController  = UINavigationController(rootViewController: viewController)
        navController.tabBarItem.image = image
        navController.navigationBar.backgroundColor = .white
        navController.tabBarItem.title = title
        return navController
    }
}
}

【问题讨论】:

  • 你的意思是状态栏?
  • 看起来您在选项卡视图中有一个导航控制器,但没有设置“顶部栏下”或其他内容。您能否提供更多关于您如何设置视图层次结构的详细信息?
  • 是的,所以它的导航控制器-> tabBar 控制器-> 导航控制器-> 视图控制器。每当我向导航栏添加属性时,屏幕上都会出现两个导航栏。我只能影响底部的。

标签: ios swift xcode constraints navigationbar


【解决方案1】:

您始终可以使用“调试视图层次结构”xCode 工具来查看屏幕中的视图层次结构。

只需在模拟器或设备上运行应用程序,然后在屏幕处于活动状态时单击“调试视图层次结构”。

您可以在此处旋转屏幕并查看所有活动图层。选择图层后,您可以在左侧栏的层次结构中检查其名称和位置。

【讨论】:

  • 谢谢!我发现有两个不同级别的 UInavigation 视图控制器,并且都显示一个在另一个之上。我不知道如何解决它
【解决方案2】:

嘿伙计们,我想通了!我的错误是在将视图控制器设置在那里之前,我将原始 TabBarController 转换为 UINavigationController。因此有一个来自错误 UINavController 的导航栏和来自我在每个视图控制器上投射的导航控制器的另一个导航栏。

【讨论】:

    猜你喜欢
    • 2020-02-26
    • 2018-02-01
    • 1970-01-01
    • 1970-01-01
    • 2021-02-07
    • 1970-01-01
    • 2011-03-13
    • 2011-03-12
    • 2013-05-16
    相关资源
    最近更新 更多