2017-02-23 113 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」,然後運行 –

相關問題