首页 > 解决方案 > 虽然当前导航然后显示视图控制器栏按钮不来,为什么在 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)
    
})
}

请在这里用代码建议

标签: swiftuinavigationcontroller

解决方案


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)

推荐阅读