故事板或SEGUE从视图控制器到的TabBar控制器
问题描述:
我想实现从视图控制器的按钮赛格瑞/故事板在迅速3故事板或SEGUE从视图控制器到的TabBar控制器
标签栏控制器(首页)这是我的代码标志
@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控制器?
答
尝试下面的步骤,
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()
ü需要创建的TabBar类从ViewController导航到TabBarcontroller –
我已经创建了一个HomeViewController.swift。只是为了缩短我的问题:如何从视图控制器中继续(如果使用segue)或故事板(如果使用故事板)从视图控制器到TAB栏控制器?我知道如何从视图控制器继续到另一个,但在标签栏我不知道。 – Lonewulf
我认为你已经创建了新的类下的Tabbar,链接 - https://drive.google.com/file/d/0B1bdnxm63q27cE02dzNod2Yyd3M/view?usp=sharing –