我分類了一個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")
}
}
我不需要我的細胞可以選擇。我只需要標籤即可。
你在哪裏打電話從渲染?你是否添加識別器作爲單元格在行方法中創建的單元格? –