2017-01-10 16 views
1

ログインボタンを押してホームビューコントローラに移動したときにナビゲーションバーが表示されず、私のストーリーボードをセットアップしてすべてをうまく入れましたが、この時点で固まっていると思いますコード。ナビゲーションが表示されないXcode 8.1 iOS 10 Swift 3

実際にはセグはありませんが、代わりにコーディングがあります。ナビゲーションの仕組みはどうですか?私はナビゲーション

let vc = self.storyboard?.instantiateViewController(withIdentifier: "Home") 
self.present(vc!, animated: true, completion: nil) 

Diagram of the application page flow

@IBAction func loginAction(_ sender: Any) { 

    if self.emailTextField.text == "" || self.passwordTextField.text == "" { 

     //Alert to tell the user that there was an error because they didn't fill anything in the textfields because they didn't fill anything in 

     let alertController = UIAlertController(title: "Error", message: "Please enter an email and password.", preferredStyle: .alert) 

     let defaultAction = UIAlertAction(title: "OK", style: .cancel, handler: nil) 
     alertController.addAction(defaultAction) 

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

    } else { 

     FIRAuth.auth()?.signIn(withEmail: self.emailTextField.text!, password: self.passwordTextField.text!) { (user, error) in 

      if error == nil { 

       //Print into the console if successfully logged in 
       print("You have successfully logged in") 

       //Go to the HomeViewController if the login is sucessful 


       let vc = self.storyboard?.instantiateViewController(withIdentifier: "Home") 
       self.present(vc!, animated: true, completion: nil) 

      } else { 

       //Tells the user that there is an error and then gets firebase to tell them the error 
       let alertController = UIAlertController(title: "Error", message: error?.localizedDescription, preferredStyle: .alert) 

       let defaultAction = UIAlertAction(title: "OK", style: .cancel, handler: nil) 
       alertController.addAction(defaultAction) 

       self.present(alertController, animated: true, completion: nil) 
      } 
     } 
    } 
} 
+0

ナビゲーションコントローラにはナビゲーションバーを表示するオプションがあります。チェックされているかどうかを確認してください。 – Amanpreet

+0

質問が更新され、ナビゲーションバーが有効になっていることを確認しました –

+0

画像が表示される場合があります –

答えて

0

あなたのコードを置き換えます。このコードで

let vc = self.storyboard?.instantiateViewController(withIdentifier: "Home") 
self.present(vc!, animated: true, completion: nil) 

を:

let vc : YourViewController = self.storyboard?.instantiateViewController(withIdentifier: "Home")as! YorViewController 
let navController = UINavigationController(rootViewController: vc) 
self.present(navController, animated: true, completion: nil) 

あなただけのアウトナビゲーションとビューコントローラを提示しようとしています。プログラムでナビゲーションを実行すると、ナビゲーションバーが表示されます。

+1

Thankyousomuchhhhhhhhhh <3 –

+0

ようこそ:)答えを投票してください。 – Amanpreet

+0

私は15の評判を持っていませんので、私は投票できません:(しかし、私は一度私は15+評判の高すぎる再度得ました:) –

0

を実行するために使用

コードあなたは本当にnavigationControllerを使用していますか?もしそうなら、それはpresentではなくpushViewControllerでしょうか?

navigationController?.pushViewController(vc, animated: true) 
関連する問題