我有一个 UITable
,里面有多个标签和 TextView 。我想要在触发 touchupinside 事件时调用一个方法。我使用了 targetForAction
但我无法在其中指定 touchUpInside
事件。并且 textview 不可编辑
总的来说,我希望按钮对 addTarget
的作用由 textview 和标签完成。请帮助我
最佳答案
添加Gesture
并尝试
let tap = UITapGestureRecognizer(target: self, action: #selector(self.doubleTapped(_:)))
tap.numberOfTapsRequired = 1
yourlabel.tag = indexPath.row
yourlabel.isUserInteractionEnabled = true
yourlabel.addGestureRecognizer(tap)
调用方法如
func doubleTapped(_ recognizer: UITapGestureRecognizer) {
print(recognizer.view!.tag)
}
对于 TextView
添加 yourTextView.delegate = self
func textViewDidChange(_ textView: UITextView) {
//do continue your work
}
您可以查看其他此类方法here .
关于ios - 快速将目标添加到 UITextView 和 UILabel,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37461217/