簡體   English   中英

如何在TableView的CollectionView中獲取圖像的索引路徑?

[英]How to get a image's indexpath in CollectionView in TableView?

在我的程序中,TableView的每一行都有一個Collection,每個CollectionView都有多個圖像。 我已經在collectionView(_:, cellForItemAt:)方法中為圖像設置了TagUITapGestureRecognizer ,但是Tag只能表示圖像在CollectionView中的位置。 我如何知道單擊圖像在表格中的位置,並將TableView行和Collection行傳遞給UITapGestureRecognizer(target:, action: #selector())方法?

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

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

您可以在此處找到表格視圖單元格行

您可以執行以下操作:

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))
 }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM