gpt4 book ai didi

ios - 检测在 `View` 上点击了哪个 `Cell`

转载 作者:搜寻专家 更新时间:2023-11-01 05:54:37 24 4
gpt4 key购买 nike

我在一个 Cell 上有三个 UIImageView 当我点击单元格上的任何一个 UIImageView 时,我想检测在 onCellSelection< 上点击了哪个,而不是在每个 UIImageview

上放置一个 UITapGestureRecognizer
func SocialViewRow(address: SocialMedia)-> ViewRow<SocialMediaViewFile> {

let viewRow = ViewRow<SocialMediaViewFile>() { (row) in

row.tag = UUID.init().uuidString
}
.cellSetup { (cell, row) in
// Construct the view
let bundle = Bundle.main
let nib = UINib(nibName: "SocialMediaView", bundle: bundle)

cell.view = nib.instantiate(withOwner: self, options: nil)[0] as? SocialMediaViewFile
cell.view?.backgroundColor = cell.backgroundColor
cell.height = { 50 }
print("LINK \(address.facebook?[0] ?? "")")

cell.view?.iconOne.tag = 90090

//self.itemDetails.activeURL = address

let openFace = UITapGestureRecognizer(target: self, action: #selector(QuickItemDetailVC.openFace))
let openT = UITapGestureRecognizer(target: self, action: #selector(QuickItemDetailVC.openTwit))
let you = UITapGestureRecognizer(target: self, action: #selector(QuickItemDetailVC.openYouYub))

cell.view?.iconOne.addGestureRecognizer(openFace)

cell.view?.iconTwo.addGestureRecognizer(openT)
cell.view?.iconThree.addGestureRecognizer(you)



cell.frame.insetBy(dx: 5.0, dy: 5.0)
cell.selectionStyle = .none

}.onCellSelection() {cell,row in

//example
//print(iconTwo was clicked)


}


return viewRow
}

最佳答案

使用 UITapGestureRecogniser(或 UIButton)会是更好的方法。这些类旨在完成此类任务。

如果您仍想使用不同的方法,请将方法添加到您的单元格子类(将 imageView1、imageView2、imageView3 替换为您自己的属性)

override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
guard let touch = touches.first else { return }
let point = touch.location(in: view)
if imageView1.frame.containsPoint(point) {
// code for 1st image view
} else if imageView2.frame.containsPoint(point) {
// code for 2nd image view
} else if imageView3.frame.containsPoint(point) {
// code for 3rd image view
}
}

文档:

关于ios - 检测在 `View` 上点击了哪个 `Cell`,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56409879/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com