[英]How to find the indexpath of tableview when Collectionview is clicked which is in tabelview Cell
[英]How to get a image's indexpath in CollectionView in TableView?
在我的程序中,TableView的每一行都有一個Collection,每個CollectionView都有多個圖像。 我已經在collectionView(_:, cellForItemAt:)
方法中為圖像設置了Tag
和UITapGestureRecognizer
,但是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.