Search code examples
iosswift3tableviewcollectionview

How to find out which collection view cell is tapped inside collection view cell


I am having a table view and inside it a collection view. I want to find out which collection view cell is tapped and also indexpath.row of corresponding table view cell.(Right now what i am able to get indexpath.row of collection view cell from didSelectRowAtIndexPath() but not able to find out there in which table view cell corresponding cell is present.)


Solution

  • Try below code, let me know if it works for you:

    - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    
        UICollectionViewCell *cell = [collectionView cellForItemAtIndexPath:indexPath];
        CGRect frame = [collectionView convertRect:cell.frame toView:tblView];
        NSIndexPath *tblIndexPath = [tblView indexPathForRowAtPoint:frame.origin];
    }