Swift 4 后退按钮没有出现

Swift 4 back button doesn't appear

我有问题...我有两个 ViewController,我使用此代码从第一个 VC 传递到第二个

let storyBoard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
    let newViewController = storyBoard.instantiateViewController(withIdentifier: "EVSignInViewController") as! EVSignInViewController
    self.present(newViewController, animated: true, completion: nil)

问题是..我想在 2VC 上显示后退按钮。我已经尝试在 1st VC 上使用 Editor->Embed in->Navigation controller。我也用这个

navigationController?.setNavigationBarHidden(false, animated: true)
navigationItem.backBarButtonItem = UIBarButtonItem(title:"", style:.plain, target:nil, action:nil)

Presenting a ViewController 将以模态方式在您当前的顶部显示它。它实际上并没有将其推送到导航控制器导航堆栈上。

您要么需要 push 视图控制器

self.navigationController?.pushViewController(newViewController, animated: true)

或者将其包裹在导航控制器中然后呈现

let storyBoard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
let newViewController = storyBoard.instantiateViewController(withIdentifier: "EVSignInViewController") as! EVSignInViewController
let navigation = UINavigationController(rootViewController: newViewController)
self.present(navigation, animated: true, completion: nil)

第 2 次使用此方法 VC。

self.navigationController?.pushViewController(newViewController, animated: true)

而不是这个

self.present(newViewController, animated: true, completion: nil)

您将获得返回按钮。

试试这个

    self.navigationController?.navigationBar.isHidden = false