问题描述
说明:
我有一个 UITableViewCell
列表,每个列表都有一个 UICollectionView
和 X 数量的 UICollectionViewCell
(请参见下图以了解更多信息))
这背后的想法是能够实现带有顶部标题和水平滚动的部分 UICollectionView
一切都很好,除非我尝试聚焦 UICollectionViewCell
s(又名:CategoryCell
).UITableViewCell
获得焦点并突出显示所有内容,从而无法聚焦任何 UICollectionViewCell
s.
我尝试过的:
根据其他帖子,解决此问题的方法是在 UITableViewCell
上停用用户交互和/或将选择样式设置为无:
cell.selectionStyle = UITableViewCellSelectionStyle.None
并改为在 UICollectionViewCell
上启用用户交互.
以下是讨论它的帖子:
图像显示了我的 UITableViewController 以及我的 StoryBoard 中的所有内容.
问题很可能是您的表格视图单元格将 true
返回到 canBecomeFocused
.您可以通过实现 UITableViewDelegate
方法 tableView(_, canFocusRowAt:)
以返回 false
或通过子类化 UITableViewCell
并从 canBecomeFocused
返回 false
.
焦点引擎将尝试关注从 canBecomeFocused
返回 true
的最顶层视图,这就是它找不到您的集合视图单元格的原因:它们隐藏"在可聚焦的表格视图单元格中.如果您禁用表格视图单元格的焦点,那么焦点引擎将能够找到您的集合视图单元格.
override func tableView(tableView: UITableView, canFocusRowAtIndexPath indexPath: NSIndexPath) ->布尔{返回假}
Description:
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.
What I've tried:
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.
Question:
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
?
More:
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
}
这篇关于如何在 tvOS 的 UITableViewCell 中聚焦 UICollectionViewCell?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!