selectedViewcontroller not working for tabbarcontroller in tvOS 10

583 views Asked by At

I have a rootviewcontroller which is extending UITabBarController. It has several children viewcontrollers.

All I want is to programmatically select the 2nd/3rd/.. viewcontroller from the first one. I've used

`.selectedViewController`, `.selectedIndex`, `.navigationController.tabBarController.tabBar.selectedItem = ...` 

and all the variations on this theme. I notice the following when using

`tabBarController.selectedViewController = tabBarController.viewControllers?[1]` 

The tabBarController displays the 2nd viewcontroller for a second but goes back to the 1st viewcontroller. I have a hunch this is the focus engine but I'm lost at this point.

2

There are 2 answers

0
alina On

I was setting an UITabBarItem for each controller.

0
Tom Kidd On

Not completely sure if it's related but I had a tvOS app where I had several UIViewControllers in a UITabBarController and I stopped being able to select them in the tab bar and have the tab bar go away once I upgraded to tvOS 10.

Turns out the issue is that those screens did not have any focusable elements on them (buttons, etc.) so I had to make subclass objects for some of the views and make the canBecomeFocused property return "true".

see: How to make a UIView focusable using the focus engine on Apple TV

You have to implement a second thing to make them appear focused but if you don't actually want that you can skip it.