【发布时间】:2018-06-01 03:45:45
【问题描述】:
我有 2 个ViewControllers 正在展示一个新的ViewController。
第一个是在导航控制器中,因此它可以通过 segue 推送按预期工作。
然而,第二个来自没有导航栏的ViewController。我以编程方式呈现这种观点。但是,当提出目的地时,有两个问题......
1) 没有导航栏。 2) 显示的视图从第一个 TableViewCell 下方开始。
func goToLocation() {
let locationTableVC = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "locationProfile") as! LocationTableViewController
locationTableVC.documentId = selectedDocumentId!
self.present(locationTableVC, animated: true, completion: nil)
}
LocationTableViewController.swift
// MARK: - View Will Appear
override public func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
UIApplication.shared.statusBarStyle = .lightContent
// Make Nav Bar Translucent and Set title font/color
self.navigationController?.navigationBar.setBackgroundImage(UIImage(), for: .default)
self.navigationController?.navigationBar.shadowImage = UIImage()
self.navigationController?.navigationBar.isTranslucent = true
self.navigationController?.view.backgroundColor = .clear
self.navigationController?.navigationBar.titleTextAttributes = [NSAttributedStringKey.foregroundColor: UIColor.white, NSAttributedStringKey.font: UIFont.systemFont(ofSize: 20, weight: .semibold)]
self.navigationController?.navigationBar.backIndicatorImage = UIImage(named: "back-arrow-white")
}
【问题讨论】:
-
"1)" 很简单,它没有导航控制器,因为您没有来自该视图的导航控制器。您必须推送嵌入在 UINavigationController 中的视图控制器才能拥有一个。如果从其他视图推送时也可以解决“2)”问题。
-
@Daniel 所以如果我不想看到第一个 VC 上显示的导航栏,尽管我只是隐藏它?
-
你不需要隐藏它,只需要在需要的时候创建一个。看我的回答。
标签: ios swift uinavigationcontroller uinavigationbar segue