Swift
Swift

Reputation: 1184

While present navigation then presented viewcontroller bar button not coming, why in swift

my viewcontroller flow will be like below:

  navigationcontroller -> logoutviewcontroller ->(present) 

                       viewcontroller -> (present) logoutviewcontroller (bar button coming)
                                |
                           loginviewcontroller
                                |
                        (present) logoutviewcontroller (bar button not coming)   

logoutVC code:

  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 code: when presenting logoutVC coming but bar button not coming.. why

 @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)
    
})
}

please suggest here with code

Upvotes: 0

Views: 31

Answers (1)

Luca Sfragara
Luca Sfragara

Reputation: 634

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)

Upvotes: 1

Related Questions