簡體   English   中英

如何將LongPressGestureRecognizer添加到禁用的TextField中

[英]How to add LongPressGestureRecognizer into disabled TextField

我有isEnabled = false TextField,

現在我想添加UILongPressGestureRecognizer

在UITableViewCell內部:

override func awakeFromNib() {
    super.awakeFromNib()
    let tap = UILongPressGestureRecognizer(target: userNameTextField, action: #selector(userNamelongPressAction))
    self.addGestureRecognizer(tap)
}

但是我崩潰了

'NSInvalidArgumentException',原因:'-[UITextField userNamelongPressAction]:無法識別的選擇器已發送到實例

我能做什么? 謝謝

這是一個常見的錯誤,您將目標錯誤地添加到UITextField ,而必須將目標設置為實現方法userNamelongPressAction

此代碼假定您已在此類上下文中實現了userNamelongPressAction方法

override func awakeFromNib() {
    super.awakeFromNib()
    let tap = UILongPressGestureRecognizer(target: self, action: #selector(userNamelongPressAction))
    self.addGestureRecognizer(tap)
}

希望這個幫助

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM