0

在我的程序中,TableView的每一行都有一个Collection,每个CollectionView有几个Images。我在方法中设置了Tagand UITapGestureRecognizerfor image collectionView(_:, cellForItemAt:),但是Tag只能表示图片在CollectionView中的位置。如何知道被点击的图片在 Table 中的位置,并将 TableView 的行和 Collection 的行传递给UITapGestureRecognizer(target:, action: #selector())方法?

4

2 回答 2

0
let pointTable :CGPoint = sender.convert(sender.bounds.origin, to: self.upComing_tblView)

        let indexpath = self.upComing_tblView.indexPathForRow(at: pointTable)

你可以在这里找到表格视图单元格行

于 2018-06-11T07:20:26.567 回答
0

你可以这样做:

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))
 }
于 2018-06-11T07:25:34.693 回答