【问题标题】:Navigation bar not showing over TableView导航栏未显示在 TableView 上
【发布时间】:2018-04-30 17:59:38
【问题描述】:

我无法解释为什么这段代码不起作用。由于某种原因,导航栏是半透明的,并且 tableView 的内容正在其上滚动。

这是按钮的代码

 let outlineViewController = OutlineTableviewController()
        outlineViewController.pdfOutlineRoot = pdfoutline
        outlineViewController.delegate = self

        let nav = UINavigationController(rootViewController: outlineViewController)
        self.present(nav, animated: true, completion:nil)

这是tableView的代码

super.viewDidLoad()

    let newBackButton = UIBarButtonItem(title: "Cancel", style: UIBarButtonItemStyle.plain, target: self, action: #selector(dismissView))

    self.navigationItem.rightBarButtonItem = newBackButton

    navigationController?.navigationBar.backgroundColor = UIColor(red:0.00, green:0.51, blue:0.78, alpha:1.0)


   self.tableView.dataSource = self
   self.tableView.delegate = self

   tableView?.register(UINib(nibName: "OutlineTableViewCell", bundle: nil),
                        forCellReuseIdentifier: "OutlineTableViewCell")
}

结果如下: 背景颜色未显示,表格位于导航栏下方。

我错过了什么?

【问题讨论】:

  • 我试过你的代码,它工作正常。我认为问题出在另一个地方。您是否在其他任何地方设置了导航栏背景?

标签: ios uitableview swift3 uinavigationcontroller uinavigationbar


【解决方案1】:

感谢 trungduc 的回复。

在花了几个小时试图找出问题所在之后,我终于能够通过更改根视图中的颜色来解决这个问题。

        let nav = UINavigationController(rootViewController: oulineViewController)
        nav.navigationBar.backgroundColor = UIColor(red:0.00, green:0.51, blue:0.78, alpha:1.0)
        self.present(nav, animated: true, completion:nil)

【讨论】:

    【解决方案2】:

    您在问题中提到了一个神奇的词:“半透明”。

    我遇到了同样的问题:导航栏显示在 Storyboard 的根视图上,但是在运行模拟器时 - 视图顶部没有导航栏。这解决了它:

    Navigation Controller > Navigation Bar > UNCHECK Translucent(默认选中)。这做了两件事:

    1. 我的导航栏显示在所有后续视图中。
    2. 最顶层的子视图(在您的情况下为表格视图)现在位于 Y=0,而不是 Y=64。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-06-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多