In my program, each row of TableView has a Collection, each CollectionView has several Images. I have set Tag
and UITapGestureRecognizer
for the image in the collectionView(_:, cellForItemAt:)
method, but Tag
can only represent the position of the image in the CollectionView. How do I know the position of the clicked image in the Table and pass the row of TableView and the row of Collection to UITapGestureRecognizer(target:, action: #selector())
method?
Asked
Active
Viewed 364 times
0

K.B.
- 291
- 2
- 13
-
Give a indepath.row of tableView into collectionview tag. then you can easily get the tag from collectionview didselect method. – Vishal Patel Jun 11 '18 at 07:20
-
Do not use tap gesture recognizer on collectionView. Use didSelectItemAtIndexPath instead. Write a protocol in collectionView and confirm to methods in your tableView, every time user taps on cell in collectionView trigger the delegate with the collectionView instance and its indexPath of cell to tableView. Now in order to find the tableView cell holding the collectionView use indexPathsForRows method of tableView that should help. Or you can go back to logic of setting tag to collectionView which will represent its indexPath in tableView and rather returning collectionView return its tag – Sandeep Bhandari Jun 11 '18 at 07:20
-
@SandeepBhandari I do not want to click on the entire cell, I just want to click on the picture inside the cell. – K.B. Jun 11 '18 at 07:57
-
@jake-to : I presume that each image is in individual cell of `UICollectionView` hence u can make use of `UICollectionView` `didSelectItem` delegate method – Sandeep Bhandari Jun 11 '18 at 08:04
2 Answers
0
let pointTable :CGPoint = sender.convert(sender.bounds.origin, to: self.upComing_tblView)
let indexpath = self.upComing_tblView.indexPathForRow(at: pointTable)
you can find table view cell row here

Praveen Gowlikar
- 215
- 2
- 16
0
You can do something like this:
func imageTapped(gesture: UITapGestureRecognizer) {
let location: CGPoint = gesture.location(in: tableView)
let ipath: IndexPath? = tableView.indexPathForRow(at: location)
let cellindex: UITableViewCell? = tableView.cellForRow(at: ipath ??
IndexPath(row: 0, section: 0))
}

iVarun
- 6,496
- 2
- 26
- 34