Drew
Drew

Reputation: 1361

Segue VC With Tab App Swift

I am trying to segue between view controllers in my application, but have used a Tabbed application template. This is my first time using the tab based application, and I am having trouble calling a segue from the second VC to the first on a button click.

I have tried both creating a segue in the storyboard like so self.performSegue(withIdentifier: "SegueToCalc", sender: nil) and programmatically creating and calling the segue, but both of which load just the screen without the tab bar at the bottom. I believe their is a way to call the TabController in order to set which index is selected, but I have tried below and this does not work either:

var tabBarController: UITabBarController?
tabBarController?.selectedIndex = 0

Upvotes: 0

Views: 27

Answers (1)

Hannes
Hannes

Reputation: 3772

You’re already on the right track, however, you're creating a new UITabBarController and not accessing the one you already have. You can access a possible UITabBarController directly from it's viewControllers.

@IBAction func onButton(_ sender: Any) {
    self.tabBarController?.selectedIndex = 0
}

Upvotes: 1

Related Questions