I have a UITabBarController set up in storyboard. I want to pass a dictionary of data from the tab bar controller for use in the appropriate child tab, which is a standard UIVie
Using Swift
If you have UINavigationController
as one of the tabs in UITabBarController
, you want to get the instance of the child view controller instead of creating a new instance and push it to the navigation view controller before changing the tab view index. You can do this...
This sample code assumes the Navigation Controller is at the first tab (index 0) and "childViewController" is embedded in the Navigation Controller.
let viewControllers = self.tabBarController?.viewControllers
let navController = viewControllers![0] as! UINavigationController
let profileViewController = self.storyboard?.instantiateViewControllerWithIdentifier("childViewController") as? ProfileViewController
profileViewController!.parameter1 = "Value1"
profileViewController!.parameter2 = "Value2"
navController.pushViewController(profileViewController!, animated: true)
self.tabBarController?.selectedIndex = 0