2017-06-03 102 views
0

我有一個視圖控制器作爲我的初始視圖控制器。 有一個按鈕(GO按鈕),當用戶點擊時,它應該去另一個視圖控制器(我們稱之爲目標視圖控制器與標籤'這是我想去')。同時我想通過一個Tabbar控制器。原因是我想我的導航堆棧中有tabbar,當用戶在目標視圖控制器上按下時,它必須轉到tabbar控制器。圖片顯示了我想要的。我可以在導航堆棧中跳過tabbar的時候做些什麼?導航通過視圖控制器,而跳過一個 - iOS

enter image description here

+1

您可以創建一個視圖控制器數組並將其設置爲'navigationController.viewControllers'。 –

回答

1

你可以做到這一點很容易GO按鈕的IBAction內:

@IBAction func goTapped(_ sender: UIButton) { 

    let storyboard = UIStoryboard(name: "Main", bundle: nil) 
    let vc1 = storyboard.instantiateViewController(withIdentifier: "myTabBarViewController") 
    let vc2 = storyboard.instantiateViewController(withIdentifier: "myGoalViewController") 
    let controllers = [vc1, vc2] 
    self.navigationController!.setViewControllers(self.navigationController!.viewControllers + controllers, animated: true) 
} 

祝你好運!

1

將DestinationViewController可以手動:

if let destinationViewController = self.storyboard?.instantiateViewController(withIdentifier: "Storyboard ID of DestinationViewController") { 
    self.navigationController?.pushViewController(destinationViewController, animated: true) 
} 

而在你DestinationViewController,插入(或者,你可以直接在故事板製作SEGUE從FirstViewController到DestinationViewController) TabbarController到導航序列在視圖後手動出現,然後您可以返回到TabbarController:

class DestinationViewController: UIViewController { 
    //...... 
    override func viewDidAppear(_ animated: Bool) { 
     super.viewDidAppear(animated) 

     if self.isBeingPresented || self.isMovingToParentViewController { 
      var viewControllers = self.navigationController?.viewControllers 

      if let index = viewControllers?.endIndex.advanced(by: -1), 
       let tabBarController = self.storyboard?.instantiateViewController(withIdentifier: "Storyboard ID of TabBarController") { 
       viewControllers?.insert(tabBarController, at: index) 
       self.navigationController?.viewControllers = viewControllers! 
      } 
     } 
    } 
    //...... 
} 
相關問題