我有问题...我有两个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)
问题是..我想在第二个VC上显示后退按钮。我已经尝试在1st VC上使用Editor-> Embed in-> Navigation controller。我也用这个
navigationController?.setNavigationBarHidden(false, animated: true)
navigationItem.backBarButtonItem = UIBarButtonItem(title:"", style:.plain, target:nil, action:nil)
答案 0 :(得分:3)
Presenting
,一个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)
答案 1 :(得分:0)
将此方法用于当前的第二个VC。
self.navigationController?.pushViewController(newViewController,animation:true)
代替此
self.present(newViewController,动画:true,完成:无)
您将获得返回按钮。
答案 2 :(得分:0)
尝试
self.navigationController?.navigationBar.isHidden = false