其他解决方案似乎无效。
我正在使用MasterView应用程序,以防万一。
我希望在'detailViewController'上没有导航栏,并且在以后的我使用'show'选项连接的ViewController上也没有导航栏。
这是DetailViewController:
Class DetailViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {
override func viewDidLoad() {
super.viewDidLoad()
self.navigationController?.setToolbarHidden(true, animated: true)
configureView()
}
configureView() {
// Some UI Stuff
}
}
导航栏仍然存在。
在MasterViewController中,这是prepareForSegue:
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "showDetail" {
if let indexPath = tableView.indexPathForSelectedRow {
if isFiltering() == true {
let building = filteredBuildings[(tableView.indexPathForSelectedRow?.row)!]
let controller = (segue.destination as! UINavigationController).topViewController as! DetailViewController
controller.detailBuilding = building
controller.navigationItem.leftBarButtonItem = splitViewController?.displayModeButtonItem
controller.navigationItem.leftItemsSupplementBackButton = true
rating = filteredBuildings[(tableView.indexPathForSelectedRow?.row)!].rating
print("rating was changed to \(rating)")
} else {
let building = buildings[indexPath.row]
let controller = (segue.destination as! UINavigationController).topViewController as! DetailViewController
controller.detailBuilding = building
controller.navigationItem.leftBarButtonItem = splitViewController?.displayModeButtonItem
controller.navigationItem.leftItemsSupplementBackButton = true
rating = buildings[indexPath.row].rating
print("rating was changed to \(rating)")
}
}
}
}
答案 0 :(得分:1)
隐藏导航栏工具栏与隐藏导航栏本身不同。如果要隐藏工具栏,则可以尝试使用@ Anbu.karthik在注释中建议的内容。但是,如果要隐藏 导航栏,则需要使用此代替。
navigationController?.setNavigationBarHidden(true, animated: true)
答案 1 :(得分:1)
self.navigationController?.setNavigationBarHidden(true,animation:true)