5
votes

How can I segue to a tab bar controller? Theres 2 view controllers on tabs with navigation controllers and a navigation controller on the tab bar controller.

let storyboard = UIStoryboard(name: "PendingOverview", bundle: nil)
let vc = storyboard.instantiateViewController(withIdentifier: "PendingOverviewVC") as! PendingOverViewController
let nc = UINavigationController(rootViewController: vc)
self.present(nc, animated: false, completion: nil)

Thank you

1
You have asked about segue in your question and in code you are using present? - Nirav D
Yeah sorry I was using the literal term "segue". Thanks though - Denis
Have you try my solution is it works for you? - Nirav D

1 Answers

6
votes

In Storyboard set identifier to UITabbarController and then using instantiateViewController present that UITabbarController.

let storyboard = UIStoryboard(name: "PendingOverview", bundle: nil)
let tabbarVC = storyboard.instantiateViewController(withIdentifier: "TabbarIdentifier") as! UITabbarController
if let vcs = tabbarVC.viewControllers, 
   let nc = vcs.first as? UINavigationController,
   let pendingOverVC = nc.topViewController as? PendingOverViewController {

      pendingOverVC.pendingResult = pendingResult
}
self.present(tabbarVC, animated: false, completion: nil)