Swift 情节提要或从ViewController到Tabbar Controller的分段

Swift 情节提要或从ViewController到Tabbar Controller的分段,swift,xcode,uiviewcontroller,swift3,uitabbarcontroller,Swift,Xcode,Uiviewcontroller,Swift3,Uitabbarcontroller,我想在swift 3中从视图控制器到选项卡栏控制器(主页)的按钮中实现一个segue/storyboard 这是我的登录代码 @IBAction func LogIn(_ sender: Any) { if self.emailTextfield.text == "" || self.passwordTextfield.text == "" { let alertController = UIAlertController(title: "Error", messa

我想在swift 3中从视图控制器到选项卡栏控制器(主页)的按钮中实现一个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,它是在选项卡栏控制器(灰色)中还是连接到第一个选项卡控制器?

尝试下面的步骤

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) 然后从任何viewcontroller调用该func,如下所示

let appDelegate = UIApplication.shared.delegate as! AppDelegate
appDelegate.LoginNav()

您需要创建tabbar类才能从ViewController导航到TabBarcontrollerI我已经创建了HomeViewController.swift。只是为了简化我的问题:如何从视图控制器到选项卡栏控制器(如果使用segue)或情节提要(如果使用情节提要)?我知道如何从视图控制器到另一个控制器进行分段,但在选项卡栏中我不知道。我想您已经在UITabBarController下为选项卡栏创建了新类,链接-实际上,您必须尝试从ViewController导航到TabBarController,但您没有从ViewController导航到ViewController,所以这里的问题是,您需要了解我所做的概述:。我已经做了这个。我接下来要做的是,在登录之后,它将直接连接到一个tabbar控制器(其中有home选项卡、profile选项卡)。问:如何从登录到选项卡栏控制器?尝试了你的建议,它给了我黑屏,有什么问题吗?我不知道我应该把我的故事板id:“MainTab”放在哪里。是在主选项卡视图控制器中还是在第一个选项卡视图控制器中?仍然,给我黑屏。为什么?选择选项卡栏控制器-->标识检查器-->给出类名-->将情节提要ID更改为“MainTab”,然后运行如果您仍然难以运行,是否可以发送示例包这是github repo。。我想在这里实现的不是视图控制器,而是登录后它将直接指向选项卡栏控制器。