iosswiftnavigationtabbarcontroller

Swift Navigation to Specific Child VC with tabBarControllers


I have a setup with a tabBarController going to four navigation controllers which contain go further to some child view controllers. In this instance, I am trying to go to one of the child view controllers of the navigation controller. I've been able to transition tabBar pages with the code. self.tabBarController?.selectedIndex = 4 But after I need to go to perform a segue to a child view controller on from this page. Any help would be greatly appreciated.

Overall tabBarController setup enter image description here

Settings Tab Controller Page with child view controllers enter image description here


Solution

  • 1) Store your tab bar child controllers as a property in an array in your UITabBarController, e.g.

    var tabViewControllers: [UIViewController]!
    

    2) After setting self.tabBarController?.selectedIndex = desiredIndex, ask target child to perform desired actions.

    let targetNavigationController = self.tabViewControllers[desiredIndex] as? UINavigationController
    let yourTargetViewController = targetNavigationController?.viewControllers.first as? YourTargetViewController
    // From here do whatever you want: call functions, perform segues, push to navigation stack or present modals, e.g.:
    yourTargetViewController?.performSegue(...)