我想在swift 3中的按钮FROM View Controller TO标签栏控制器(Home)中实现segue / storyboard
这是我的代码
@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)
我尝试使用segue
self.performSegue(withIdentifier: "Home", sender: self)
都给了我黑屏。为什么?我也有澄清。我应该在哪里连接我的segue,它是在标签栏控制器(灰色)还是第一个TAB控制器?
答案 0 :(得分:0)
尝试以下步骤,
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()