ios - UICollectionViewCell 内的 UITableView,点击单元格时所有 UITableViewCells 都突出显示

标签 ios objective-c uitableview

我正在制作一个 UICollectionView,其中一些 UICollectionViewCells 包含一个 UITableView

这很好用,一切都很好,直到我点击 UITableView 以外的其他地方的 UICollectionViewCell。这会导致在表中的所有 UITableViewCells 上调用 setHighlighted 方法。

下面是 UICollectionViewCell 的粗略图。 UITableView 仅跨越 “一号牢房”到“三号牢房”。点击此表格之外但在 UICollectionViewCell 内的任何位置会导致单元格突出显示。

-------------------------
| Title goes here       |
|                       |
-------------------------
|                       |
|   Cell one            |
-------------------------
|                       |
|   Cell two            |
-------------------------
|                       |
|   Cell three          |
-------------------------
| Button outside table  |
|-----------------------|

调用堆栈看起来像这样。

[MyTableViewCell setHighlighted:]
[UICellHighlightingSupport highlightView:]
UIApplicationMain
main

似乎 UICollectionViewCell 将突出显示命令转发给所有单元格。

我通过在我的 UITableViewCell 子类中重载 setHighlighted 方法而不调用 super 实现来解决这个问题。但这似乎有点老套,我想知道是否可以通过某种方式避免这种行为。

编辑: 我假设此行为来自 UICollectionCellView 对其所有子项调用 setHighlighted 时。据我所知,这在大多数其他情况下很有用。

最佳答案

您是否尝试过实现以下 UICollectionViewDelegate 的方法?

collectionView:shouldHighlightItemAtIndexPath:

如果您在 Collection View 中为您的 UITableView View 返回 NO,那么您应该可以继续了。

关于ios - UICollectionViewCell 内的 UITableView,点击单元格时所有 UITableViewCells 都突出显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19444454/

相关文章:

ios - 类型 'ProfilesTableViewController' 不符合 Xcode 6 GM 种子中的协议(protocol) 'UITableViewDataSource'

ios - 解析没有键的Json数组swift 4

ios-Xcode 10 : Razorpay pod "module compiled with Swift 4.1 cannot be imported by the Swift 4.2 compiler"

ios - 如何仅旋转子类 mpmovieplayer Controller 并将其他 View 固定为纵向

ios - Swift:numberOfRowsInSection 和 cellForRowAt 未被调用

ios - 如何在不添加 subview 的情况下实现UITableview seperator 'above first row'

ios - 在 UITableView 上创建一个 float 按钮

iOS:使用工厂设计模式动态更改可访问属性?

iOS 7 添加了向右滑动以从堆栈中弹出 View Controller 。是否可以通过向左滑动将其添加回去?

ios - GCD 与自定义队列