我分类了一个UITableViewCell。我试图添加手势识别器,但是当我点击它时没有任何反应。如何将TapGestureRecognizer添加到单元格内的标签?
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")
}
}
我不需要我的细胞可以选择。我只需要标签即可。
你在哪里打电话从渲染?你是否添加识别器作为单元格在行方法中创建的单元格? –