I was wondering, why UITapGestureRecognizer
doesn't work, if we make it become the member variable of a class?
Not working. hideKeyboard is not called when tapped
class TabInfoSettingsCell: UICollectionViewCell {
private let hideKeyboardTapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(hideKeyboard))
override func awakeFromNib() {
super.awakeFromNib()
self.isUserInteractionEnabled = true
self.addGestureRecognizer(hideKeyboardTapGestureRecognizer)
}
@objc private func hideKeyboard() {
print("hide keyboard")
}
Working
class TabInfoSettingsCell: UICollectionViewCell {
override func awakeFromNib() {
super.awakeFromNib()
self.isUserInteractionEnabled = true
let hideKeyboardTapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(hideKeyboard))
self.addGestureRecognizer(hideKeyboardTapGestureRecognizer)
}
@objc private func hideKeyboard() {
print("hide keyboard")
}
Do you have idea what is the reason behind, on why UITapGestureRecognizer
does not work if we make it become the member variable of a class?