gpt4 book ai didi

ios - 在 tableViewCell Swift 上点击手势

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

我想在表格 View 单元格中的图像被录音时完成一个 Action 。我通过 Storyboard 设置了轻击手势,但每次触摸单元格时它都会读取轻击。

当只有我的表格 View 单元格中的图像被录音时,如何完成点击手势?

enter image description here

  func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return generalRoomDataArr.count // your number of cell here
}




func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {


let cell = tableView.dequeueReusableCell(withIdentifier: "cell")

//Transform Data From ^ to load at the bottom
tableView.transform = CGAffineTransform (scaleX: 1,y: -1);
cell?.contentView.transform = CGAffineTransform (scaleX: 1,y: -1);
cell?.accessoryView?.transform = CGAffineTransform (scaleX: 1,y: -1);

//Set username label to display username
let usernameLabel = cell?.viewWithTag(1) as! UILabel
usernameLabel.text = generalRoomDataArr[indexPath.row].username


//Set message label to display message
let messageLabel = cell?.viewWithTag(2) as! UILabel
messageLabel.text = generalRoomDataArr[indexPath.row].message
messageLabel.numberOfLines = 0

//initialize UI Profile Image
let imageView = cell?.viewWithTag(3) as! UIImageView

//Make Porfile Image Cirlce
imageView.layer.cornerRadius = imageView.frame.size.width/2
imageView.clipsToBounds = true

//Set timeStampLabel to current time AGO
let timeStampLabel = cell?.viewWithTag(4) as! UILabel
timeStampLabel.text = generalRoomDataArr[indexPath.row].timeStamp
timeStampLabel.numberOfLines = 0


//Loading and change of Usesrs profile image on chat cell
let userProfileChatImage = generalRoomDataArr[indexPath.row].photoURL

//Load profile image(on cell) with URL & Alamofire Library



let downloadURL = NSURL(string: userProfileChatImage!)
imageView.af_setImage(withURL: downloadURL as! URL)






// your cell coding
return cell!
}






@IBAction func userPhotoTaped(_ sender: Any) {

print("tapped")
}








}//END CLASS

这个我也试过

let tapped:UITapGestureRecognizer = UITapGestureRecognizer(target: self, action: Selector(("TappedOnImage:")))
tapped.numberOfTapsRequired = 1
cell?.imageView?.addGestureRecognizer(tapped)

func TappedOnImage(sender: UITapGestureRecognizer){
print("Elltappy")
}

最佳答案

你应该这样使用。创建一个自定义单元格并且必须为 ImageView 使用 isUserInteractionEnabled,您可以处理图像点击或表格 View 确实选择操作。

class TestCell: UITableViewCell {

@IBOutlet weak var imageV: UIImageView!

override func awakeFromNib() {
super.awakeFromNib()
// You must to use interaction enabled
imageV.isUserInteractionEnabled = true
imageV.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(imageTapped(_:))))
}

func imageTapped(_ sender: UITapGestureRecognizer) {
print("image tapped")
} }

关于ios - 在 tableViewCell Swift 上点击手势,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43358238/

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