Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Determine tapped element within UICollectionViewCell

I have an UICollectionView with custom cells. When I tap a cell I get a collectionView: didSelectItemAtIndexPath:.

This doesn't allow me to determine which element inside the cell was tapped (image or label). How to determine which element within the cell was tapped?

like image 685
Razer Avatar asked Jan 31 '26 03:01

Razer


1 Answers

You have to subclass UICollectionViewCell and have these kind of objects in your UICollectioView. Then you create a delegate in the cells with methods like

- (void)collectionCell:(UICollectionViewCell *)cell didTapButtonWithIndex:(NSUInteger)index

and set your view controller as delegate for each of this cell. So you would get the action in these methods instead of collectionView: didSelectItemAtIndexPath:

like image 177
Levi Avatar answered Feb 01 '26 16:02

Levi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!