Short explanation.
I have a ContainerViewController
that I'm pushing to a navigationStack
.
The ContainerViewController
has 2 child UIViewController
. A SlidePanelViewController
(a slide-out menu) and a CenterViewController
(the content), my CenterViewController
is a UITabBarController
which currently has 2 UIViewController
.
I have a button in my menu to that I need to change the UIViewController
in my tabBarController
. However nothing happens when I call my functions.
Here's the function I am trying to call:
func premiumFormulaTapGesture() {
tabBarController?.selectedIndex = 1
}
(I also tried setting it to 0 and 2. Still with no results.) I tried putting self.
in front of it without any luck.
I also tried putting it as a function in my ContainerViewController
. But that didn't seem to work either.
Here's how I'm setting up my UITabBarController
:
var centerTabBarController: UITabBarController!
in ViewDidLoad()
:
let tabBarController = UITabBarController()
let suggestionsVC = mySuggestions_VC()
let testVC = detaiLSuggestion_VC()
let controllers = [suggestionsVC,testVC]
tabBarController.setViewControllers(controllers, animated: false)
centerViewController = tabBarController
view.addSubview(tabBarController.view)
addChildViewController(tabBarController)
my tabBarController
does show up. And I am able to manually tap the 2 buttons on it, where it switches between the viewControllers
as expected. I later plan on hiding the UITabBarController
, and use the menu. The UITabBarController
is going to be my method of changing UIViewController
from the menu.
Also just to clarify. I'm not using storyboards.
Any help changing the viewControllers
in my tabBarController
would be greatly appreciated!