gpt4 book ai didi

ios - 如何将 TapGestureRecognizer 添加到单元格内的标签?

转载 作者:行者123 更新时间:2023-11-30 13:28:04 24 4
gpt4 key购买 nike

我对 UITableViewCell 进行了子类化。我尝试添加手势识别器,但点击它时没有任何反应。

class MessagesTableViewCell: UITableViewCell {


@IBOutlet weak var nameLabel: UILabel!

var profileTap:UITapGestureRecognizer?


func render(){
if profileTap == nil {
print("Here") //prints.
profileTap = UITapGestureRecognizer()
profileTap?.addTarget(self, action: #selector(MessagesTableViewCell.profileTapped(_:)))
nameLabel.addGestureRecognizer(profileTap!)
}
}


func profileTapped(sender: UITapGestureRecognizer!){
print("tapped")
}
}

我不需要我的单元格可供选择。我只需要标签。

最佳答案

确保标签的 userInteractionEnabled 属性为 true,UILabel 默认情况下不与用户交互。

label.userInteractionEnabled = true

或者,使用 UIButton。

关于ios - 如何将 TapGestureRecognizer 添加到单元格内的标签?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36900114/

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