Reputation: 5340
I have a UITableView where each UITableViewCell contains a UICollectionView. The UICollectionView has UICollectionViewCells.
My problem is: Some of these UICollectionViewCells should react to tap-gestures, others should forward the event to the UITableViewCell (so it triggers displaying of the detail-view for that UITableViewCell).
I've been studying the apple-docs and several questions here but I can't get it to work.
(I think it should be possible to solve this generally, but just in case: Each UICollectionViewCell contains an UIImageView.)
Suggestions are very appreciated.
Upvotes: 4
Views: 2066
Reputation: 9915
If I understand you correctly, you can do it like this:
cell.userInteractionEnabled = NO
on the cells you don't want to handle events.Override hitTest
in your UICollectionView
with this method:
-(UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event
{
UIView *hitTest = [super hitTest:point withEvent:event];
return hitTest == self ? nil : hitTest;
}
So tapping anywhere outside of a cell with user interaction enabled, super
returns the collection view and we return nil
, causing the table view cell to handle the event.
Upvotes: 1
Reputation: 7494
Why don't you let only the uicollectionview cell's handle the taps and then in the callback determine what action to take. For some you could do what you do now when tapping the cell, for others whatever you want.
Upvotes: 0