我有一个带有图像和 UITextView 属性的自定义 UITableViewCell。文本视图跨越到单元格的边缘。我的问题是点击文本视图未在 didSelectRowAtIndexPath 中注册。
我怎样才能让我可以“点击”我的文本视图?
For UITextView
set textView.userInteractionEnabled = false
如果你有UITextField
, set textField.userInteractionEnabled = false
.
如果您希望 textView 或 textField 在点击单元格后可编辑,请执行以下操作:
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
tableView.deselectRowAtIndexPath(indexPath, animated: true)
let cell = tableView.cellForRowAtIndexPath(indexPath)! as UITableViewCell
// find first textField inside this cell and select it
for case let textField as UITextField in cell.subviews {
textField.userInteractionEnabled = true
textField.becomeFirstResponder()
return
}
// find first textView inside this cell and select it
for case let textView as UITextView in cell.subviews {
textView.userInteractionEnabled = true
textView.becomeFirstResponder()
return
}
}
然后确保在完成编辑后禁用用户交互:
func textFieldDidEndEditing(textField: UITextField) {
textField.userInteractionEnabled = false
// rest of the function
}
func textViewDidEndEditing(textView: UITextView) {
textView.userInteractionEnabled = false
// rest of the function
}
不要忘记设置UITextFieldDelegate
and/or UITextViewDelegate
我希望这对某人有帮助:)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)