迅速な3のビューコントローラーからタブバーコントローラー(ホーム)へのボタンにセグエ/ストーリーボードを実装したい
これは私のサインインコードです
@IBAction func LogIn(_ sender: Any) {
if self.emailTextfield.text == "" || self.passwordTextfield.text == "" {
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("You have successfully logged in")
//this is my storyboard but it gives me black screen
let vc = self.storyboard?.instantiateViewController(withIdentifier: "Home")
self.present(vc!, animated: true, completion: nil)
} else {
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)
}
}
}
}
絵コンテを使ってみました
let vc = self.storyboard?.instantiateViewController(withIdentifier: "Home")
self.present(vc!, animated: true, completion: nil)
セグエを使ってみました
self.performSegue(withIdentifier: "Home", sender: self)
両方とも私に黒い画面を与えます。どうして?私にも説明があります。セグエはどこに接続すればよいですか?タブバーコントローラー(灰色)にありますか、それとも最初のTABコントローラーに接続しますか?
以下の手順をお試しください
1)AppDelegateクラスで新しい関数を作成します
func LoginNav()
{
self.window = UIWindow(frame: UIScreen.main.bounds)
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let mainViewController = storyboard.instantiateViewControllerWithIdentifier("MainTab") as! tabbarControllerViewController // U have to create tabbarControllerViewController for ur TabBarView
self.window?.rootViewController = mainViewController
self.window?.makeKeyAndVisible()
}
2)次に、以下のような任意のビューコントローラからその関数を呼び出します
let appDelegate = UIApplication.shared.delegate as! AppDelegate
appDelegate.LoginNav()
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加