TabBarController? .SelectedIndex does not switch VC

I have a TabBarController built into the container view. The first tab has a collection view, and on didselectitematindex I call

tabBarController?.selectedIndex = 1

and it will successfully switch to another controller. HOWEVER, when I call

tabBarController?.selectedIndex = 0

it does not switch to index 0. In fact, it does nothing. I tried putting the button on selectedIndex 2 and calling this command, but it does not work. I tried adding myself. on a call but not working. I tried to call a function that makes a call, but that does not work either. I also made sure my tabBarController has the storyboard identifier "tabBarController". My tabBarController doesn't have a class attached to it, but I don't think it is needed because the first View controller controller worked without it.

What is wrong here?

I think it matters why it doesn't work if someone can give me another way to switch view controllers programmatically.

Let me know if you need more information.

Project

located here on github https://github.com/applegaming/hots-buddy

+4
source share
1 answer

Because you do not need to call TabBarController using self, because you are still in the TabBarController class.

Therefore you should use:

self.selectedIndex = 1
+5
source

Source: https://habr.com/ru/post/1653548/


All Articles