I have a list of UITableViewCell
s that have each have a UICollectionView
with X amount of UICollectionViewCell
s (see image below for more clarity)
The idea behind this is to be able to implement sections with a header on top and a horizontal scrolling UICollectionView
Everything is working great, except when I try to focus the UICollectionViewCell
s (aka: CategoryCell
). The UITableViewCell
gets focused and highlights all the content making it impossible to focus any of the UICollectionViewCell
s.
According to other posts the fix for this would be deactivate User Interaction and/or set the selection style to none on the UITableViewCell
:
cell.selectionStyle = UITableViewCellSelectionStyle.None
and to enable User Interaction on the UICollectionViewCell
instead.
Here are posts that talk about it:
UITableViewCell with UITextField losing the ability to select UITableView row?
How can I disable the UITableView selection highlighting?
I've attempted to implemen these solutions without success.
What step did I miss? Does the fix not work on tvOS? How do I focus my UICollectionViewCell
that is in a UICollectionView
that is in a UITableViewCell
?
Image showing my UITableViewController and all it's contents from my StoryBoard.
The problem is most likely that your table view cells are returning true
to canBecomeFocused
. You can disable that by either implementing the UITableViewDelegate
method tableView(_, canFocusRowAt:)
to return false
, or by subclassing UITableViewCell
and returning false
from canBecomeFocused
.
The focus engine will try to focus on the top-most view that returns true
from canBecomeFocused
, which is why it can't find your collection view cells: they're "hidden" inside the focusable table view cells. If you disable focus on the table view cells, then the focus engine will be able to find your collection view cells.
override func tableView(tableView: UITableView, canFocusRowAtIndexPath indexPath: NSIndexPath) -> Bool {
return false
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With