我有2 ViewController
个呈现新的ViewController
。
第一个是在导航控制器中,因此它可以按预期的方式使用segue push。
第二个来自ViewController
没有导航栏。我以编程方式呈现此视图。但是,当目的地出现时,有2个问题......
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")
}
答案 0 :(得分:1)
使用UINavigationController推送你的UIViewController,如下所示:
func goToLocation() {
let locationTableVC = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "locationProfile") as! LocationTableViewController
locationTableVC.documentId = selectedDocumentId!
let navigationController = UINavigationController(rootViewController: locationTableVC)
self.present(navigationController, animated: true, completion: nil)
}