导航栏没有显示在TableView上

问题描述 投票:1回答:2

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

这是Button的代码

 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")
}

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

我错过了什么?

enter image description here

ios uitableview swift3 uinavigationcontroller uinavigationbar
2个回答
0
投票

谢谢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)

0
投票

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

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

导航控制器>导航栏> UNCHECK半透明(默认选中)。这做了两件事:

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

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.