作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我对 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/
我是一名优秀的程序员,十分优秀!