I have a UITextView
connected from Storyboard, call it txtView
. In my ViewController
I set the delegate like txtView.delegate = self
.
The view controller fires method like textViewDidBeginEditing
and textViewDidChange
, but not func textView(_ textView: UITextView, shouldChangeTextIn range: NSRange, replacementText text: String) -> Bool
Yes, I did set the delegate
in my view controller.
Yes, I did put UITextViewDelegate
in my class declaration
No, I did not confuse UITextView
with UITextField
.
Any idea? Thanks!
class ViewController: UIViewController, UITextViewDelegate, UIGestureRecognizerDelegate {
@IBOutlet weak var txtView: UITextView!
override func viewDidLoad() {
super.viewDidLoad()
txtView.delegate = self
txtView.becomeFirstResponder()
txtView.text = "txt"
}
func textViewDidChange(_ textView: UITextView) {
print("THIS PRINTS")
}
func textView(_ textView: UITextView, shouldChangeTextIn range: NSRange, replacementText text: String) -> Bool {
print("WHY DOESN'T THIS GET CALLED?")
return true
}
}