Search code examples
iosswiftstoryboarduistoryboardsegue

Segue to a view controller embedded with a tab and navigation controller


The Problem Image

Hello so basically i'm trying to segue from 1 to 2 and show that screen when the button is clicked. What is happening is that the tab controller is not shown but the navigation is when it segued back to view controller 2. I'm not sure if this should be done programmatically or through the storyboard but I tried searching for a solution online and I haven't seen anybody explain this broadly.


Solution

  • You have to change the tabBarController selected item index programmatically like this when the button is tapped,

    self.tabBarController?.selectedIndex = 1 // 0 or 1 as you have two tab items

    And you have to remove the segue for that ViewController 2 as it is the first ViewController in that tab so once you set the selectedIndex of tabBarController you will get that ViewController