2017-02-23 116 views
0

我想实现从视图控制器的按钮赛格瑞/故事板在迅速3故事板或SEGUE从视图控制器到的TabBar控制器

My 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) 

我尝试使用赛格

self.performSegue(withIdentifier: "Home", sender: self) 

都给我黑屏。为什么?我也有一个澄清。我应该在哪里连接我的segue,是在标签栏控制器(灰色)还是第一个TAB控制器?

+0

ü需要创建的TabBar类从ViewController导航到TabBarcontroller –

+0

我已经创建了一个HomeViewController.swift。只是为了缩短我的问题:如何从视图控制器中继续(如果使用segue)或故事板(如果使用故事板)从视图控制器到TAB栏控制器?我知道如何从视图控制器继续到另一个,但在标签栏我不知道。 – Lonewulf

+0

我认为你已经创建了新的类下的Tabbar,链接 - https://drive.google.com/file/d/0B1bdnxm63q27cE02dzNod2Yyd3M/view?usp=sharing –

回答

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)然后调用FUNC从任何视图 - 控制像下面

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

我很困惑我应该在哪里放置我的故事板ID:“MainTab”。在维护视图控制器或第一个选项卡视图控制器中? – Lonewulf

+0

不过,给我黑屏。为什么? – Lonewulf

+0

选择标签栏控制器 - >身份检查器 - >提供班级名称 - >更改故事板ID为“MainTab”,然后运行 –

相关问题