[英]How to make a UITextView detect the click on table cell
I am working on a project and one of the table views the text for it is a UITextView, but on the other one is a UILabel.我正在开发一个项目,其中一个表视图的文本是 UITextView,但另一个是 UILabel。 The UILabel detects the click from the user as a click on the table cell, but the UITextView doesn't.
UILabel 将用户的点击检测为对表格单元格的点击,但 UITextView 没有。 Why is this happening?
为什么会这样? Is there any way to fix it?
有什么办法可以解决吗?
Ensure the isSelectable property of your textView is true.确保 textView 的 isSelectable 属性为真。
I figure it out, the cell view and text view are both scrow views and always will have conflict, so I need to uncheck the UserInteractions and Multiple Touch of the text view, booth set to false我想通了,单元格视图和文本视图都是scrow视图,总是会有冲突,所以我需要取消选中文本视图的UserInteractions和Multiple Touch,将booth设置为false
Try that试试看
yourTextView.addTarget(self, action: #selector(myTargetFunction), for: .touchDown)
@objc func myTargetFunction(textField: UITextView) {
print("myTargetFunction")
} }
I'm not sure from your question whether you're talking about selection on the UITableView
row or the UITextView
/ UILabel
itself.我不确定您是在谈论
UITableView
行还是UITextView
/ UILabel
本身的选择。
If you're trying to set up a gesture recognizer on the UILabel
or UITextView
, I'm wondering if that's necessary or if you could just use didSelectRowAtIndexPath
in your view controller.如果您尝试在
UILabel
或UITextView
上设置手势识别器,我想知道这是否有必要,或者您是否可以在视图 controller 中使用didSelectRowAtIndexPath
。
eg例如
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let cell = tableView.cellForRow(at: indexPath)
yourMethodHere(for: cell)
}
Then you'd define in yourMethodHere()
what behavior you want to happen when the cell is selected.然后,您将在
yourMethodHere()
中定义选择单元格时希望发生的行为。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.