UICollectionViewCell中的UITableView,点击单元格时会突出显示所有UITableViewCell [英] UITableView inside UICollectionViewCell, all UITableViewCells are highlighted when tapping the cell

查看:276
本文介绍了UICollectionViewCell中的UITableView,点击单元格时会突出显示所有UITableViewCell的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am making a UICollectionView where some of the UICollectionViewCells contain a UITableView.

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

This works great, and everything is fine until I tap the UICollectionViewCell somewhere else than the UITableView. This causes the setHighlighted method to be called on all UITableViewCells in the table.

以下是 UICollectionViewCell 的粗略概述。 UITableView 仅从
cell one跨越到cell three。点击此表外的任何位置,但在 UICollectionViewCell 内部会导致单元格突出显示。

Below is a rough scetch of the UICollectionViewCell. The UITableView only spans from "cell one" to "cell three". Tapping anywhere outside this table, but inside the UICollectionViewCell causes the cells to be highlighted.

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

调用堆栈看起来像这样。

The call stack looks something like this.

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

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

It seems like the UICollectionViewCell forwards a highlight command to all the cells.

我通过在 UITableViewCell 子类中重载 setHighlighted 方法解决了这个问题而没有调用超级实施。这似乎有点hacky,我想知道这种行为是否可以以某种方式避免。

I worked around the issue by overloading the setHighlighted method in my UITableViewCell subclass and not calling the super implementation. This seems a bit hacky though, and I wonder if this behavior can be avoided somehow.

编辑:
我假设这种行为来自 UICollectionCellView 在其所有子节点上调用setHighlighted时。在大多数其他情况下,我理解这一点很有用。

I assume this behavior comes from when the UICollectionCellView calls setHighlighted on all its children. Which I understand is useful in most other cases.

推荐答案

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

Have you tried implementing the following UICollectionViewDelegate's method?

collectionView:shouldHighlightItemAtIndexPath:

如果在集合视图中为 UITableView 视图返回NO,那么你应该好好去。

If you return NO for your UITableView views in the collection view, then you should be good to go.

这篇关于UICollectionViewCell中的UITableView,点击单元格时会突出显示所有UITableViewCell的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆