I am making a UICollectionView where some of the UICollectionViewCells contain a UITableView.
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.
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
It seems like the UICollectionViewCell forwards a highlight command to all the cells.
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.
EDIT:
I assume this behavior comes from when the UICollectionCellView calls setHighlighted on all its children. Which I understand is useful in most other cases.