私は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")
}
}
セルを選択する必要はありません。私はラベルが必要です。
?あなたは、行メソッドのためにあなたのセルで作成されているセルとしてレコグナイザを追加していますか? –