I have a custom UITableViewCell with an image and UITextView property. The textview spans to the edge of the cell. My problem is tapping the textview does not register in didSelectRowAtIndexPath.
How can I make it so that I can "click through" my textview?
For UITextView
set textView.userInteractionEnabled = false
and if you have UITextField
, set textField.userInteractionEnabled = false
.
If you want the textView or textField to be editable after the cell with it is tapped, do something like this:
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
}
}
Then make sure to disable user interaction after you finish editing:
func textFieldDidEndEditing(textField: UITextField) {
textField.userInteractionEnabled = false
// rest of the function
}
func textViewDidEndEditing(textView: UITextView) {
textView.userInteractionEnabled = false
// rest of the function
}
Don't forget to set the UITextFieldDelegate
and/or UITextViewDelegate
I hope this helped someone :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With