导航栏未显示在 TableView 上
Navigation bar not showing over TableView
我无法解释为什么这段代码不起作用。出于某种原因,导航栏是半透明的,table视图的内容在它上面滚动。
这里是按钮的代码
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")
}
结果如下:
背景颜色未显示,table 位于导航栏下方。
我错过了什么?
感谢 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)
您在问题中提到了神奇的词:"translucent."
我遇到了同样的问题:导航栏显示在 Storyboard 的根视图上,但是当 运行 模拟器时 - 视图顶部没有导航栏。这解决了它:
Navigation Controller > Navigation Bar > UNCHECK Translucent(默认选中)。这做了两件事:
- 我的导航栏显示在所有后续视图中。
- 最顶层的子视图(在您的例子中是表格视图)现在位于 Y=0,而不是 Y=64。
我无法解释为什么这段代码不起作用。出于某种原因,导航栏是半透明的,table视图的内容在它上面滚动。
这里是按钮的代码
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")
}
结果如下: 背景颜色未显示,table 位于导航栏下方。
我错过了什么?
感谢 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)
您在问题中提到了神奇的词:"translucent."
我遇到了同样的问题:导航栏显示在 Storyboard 的根视图上,但是当 运行 模拟器时 - 视图顶部没有导航栏。这解决了它:
Navigation Controller > Navigation Bar > UNCHECK Translucent(默认选中)。这做了两件事:
- 我的导航栏显示在所有后续视图中。
- 最顶层的子视图(在您的例子中是表格视图)现在位于 Y=0,而不是 Y=64。