swift - 虽然当前导航然后显示视图控制器栏按钮不来,为什么在 swift
问题描述
我的视图控制器流程如下:
navigationcontroller -> logoutviewcontroller ->(present)
viewcontroller -> (present) logoutviewcontroller (bar button coming)
|
loginviewcontroller
|
(present) logoutviewcontroller (bar button not coming)
注销VC代码:
override func viewDidLoad() {
super.viewDidLoad()
navigationItem.leftBarButtonItem = UIBarButtonItem(title: "logout", style: .plain, target: self, action: #selector(handleLogout))
}
@objc func handleLogout(){
let vc = self.storyboard?.instantiateViewController(withIdentifier: "ViewController") as! ViewController
self.present(vc, animated: true, completion: nil)
}
loginVC 代码:当出现 logoutVC 来但条形按钮不来时.. 为什么
@IBAction func loginButn(_ sender: Any) {
guard let email = emailTf.text, let password = passwordTf.text
else {
print("form is not valid")
return
}
Auth.auth().signIn(withEmail: email, password: password, completion: { (user, error) in
if error != nil{
print("login adding error: \(String(describing: error))" as Any)
return
}
print("login sucessfully")
let vc = self.storyboard?.instantiateViewController(withIdentifier: "LogOutViewController") as! LogOutViewController
self.present(vc, animated: true, completion: nil)
})
}
请在这里用代码建议
解决方案
If by bar button you mean the navigationController
's navigationBar
, you don't need to present the ViewController
but you need to use
self.navigationController?.pushViewController(vc, animated: true)
推荐阅读
- python - 需要同时运行2个函数,但是它们只能一个接一个地运行
- android - 如何从应用程序内部关闭应用程序通知
- jquery - 如何自动化不同复选框的直接输出?
- css - 使底部表(弹出窗口)粘在按钮上(角材料)
- python-3.x - Pandas Dataframe 到 sql 表需要帮助:
- java - Android CircularReveal 错误:在同一视图上启动另一种类型的动画师后无法正常工作
- apache-spark - java.lang.OutOfMemory:spark-submit 中的 Java 堆空间错误
- c# - 在构建 docker-compose v2 期间访问 docker 网络?
- java - xml的注释行
- c - 在 ZGM130S(z-wave 模块)中实现电容感应 (CSEN) 外设