【问题标题】:How to focus a UICollectionViewCell in UITableViewCell in tvOS?如何在 tvOS 的 UITableViewCell 中聚焦 UICollectionViewCell?
【发布时间】:2017-01-21 08:36:10
【问题描述】:

说明:

我有一个UITableViewCells 列表,每个UICollectionView 的数量为UICollectionViewCells(请参阅下图以获得更清晰的信息)

这背后的想法是能够实现顶部带有标题和水平滚动的部分UICollectionView

一切都很好,除了当我试图集中UICollectionViewCells(又名:CategoryCell)。 UITableViewCell 获得焦点并突出显示所有内容,从而无法集中任何 UICollectionViewCells。

我尝试过的:

根据其他帖子,解决此问题的方法是停用用户交互和/或将UITableViewCell 上的选择样式设置为无:

cell.selectionStyle = UITableViewCellSelectionStyle.None

并改为在 UICollectionViewCell 上启用用户交互。

以下是讨论它的帖子:

UITableViewCell with UITextField losing the ability to select UITableView row?

How can I disable the UITableView selection highlighting?

我尝试实施这些解决方案但没有成功。

问题:

我错过了哪一步?修复程序不适用于 tvOS 吗?如何将 UICollectionViewCell 中的 UICollectionView 集中在 UITableViewCell 中?

更多:

图片显示了我的 UITableViewController 以及我的 StoryBoard 中的所有内容。

【问题讨论】:

    标签: swift uitableview uicollectionview uicollectionviewcell tvos


    【解决方案1】:

    问题很可能是您的表格视图单元格将true 返回到canBecomeFocused。您可以通过实现UITableViewDelegate 方法tableView(_, canFocusRowAt:) 以返回false 或通过子类化UITableViewCell 并从canBecomeFocused 返回false 来禁用它。

    焦点引擎将尝试关注从canBecomeFocused返回true的最顶层视图,这就是它找不到您的集合视图单元格的原因:它们“隐藏”在可聚焦的表格视图中细胞。如果您禁用对表格视图单元格的焦点,则焦点引擎将能够找到您的集合视图单元格。

    override func tableView(tableView: UITableView, canFocusRowAtIndexPath indexPath: NSIndexPath) -> Bool {
        return false
    }
    

    【讨论】:

    • 我已经尝试过了,但没有成功。当我使用 siri remote 尝试在收集单元之间导航时,我的收集单元无法聚焦。我可以在表格视图中上下滚动,仅此而已。任何帮助表示赞赏。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多