Unable to focus UICollectionViewCell inside UITableViewCell

so i am learning new tvOS. Because I wanted to reproduce the horizontal section of the app store’s feature (for example, β€œBest New Apps”)

My plan was to use a UITableView to create a basic structure (rows) and use a UICollectionView for all the individual horizontal scrollable elements.

Unfortunately, tvOS always focuses the UITableViewCell, not the UICollectionViewCell inside. I already read about

override var preferredFocusedView: UIView? { return aView } 

Thus, using this inside my controller is very difficult to get the right spy.

Is there anything that I could study, or can someone point me in the right direction? Iterating over all the subzones until I get the right one seems like a bad idea.

Thanks a lot!

+6
source share
2 answers

I tried a similar situation when I had a CollectionView in a CollectionView to get the setup you described. Let them be called innerCV and externalCV. To force innerCV to be focused rather than external CV cells, I set this delegate method to return false for externalCV.

 - (BOOL)collectionView:(UICollectionView *)collectionView canFocusItemAtIndexPath:(NSIndexPath *)indexPath { return NO; } 

In turn, innerCV cells are now focusable rather than external cells.

The credit for this belongs to Apple. I used their sample project as a guide to get started. Check out Focus samples as part of your project.

Project Example: Apple tvOS UIKitCatalog

+13
source

I used a different approach.

Setting the tableview selection property to No Selection in the storyboard makes the focusing mechanism focus on the UICollectionViewCell rather than the UITableViewCell.

Hope this helps :)

Picture

+1
source

All Articles