E
E
Emil2021-06-12 16:03:42
Swift
Emil, 2021-06-12 16:03:42

How to track the change of Text View text?

Greetings, if everything is clear with the usual Text Field, and by displaying IBOutlet & @IBAction you can easily track changes, then what about the Text View? IBOutlet outputs that the action is not available. I read somewhere what needs to be done through delegates, but this is some kind of dense forest for me now. I would really appreciate an explanation, thanks in advance!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergio, 2021-06-12
@DyadyaEmil

You need to inherit from UITextViewDelegate and implement one method:

func textViewDidChange(_ textView: UITextView) {
    // ...
}

It is called when the text in the text view changes.
https://developer.apple.com/documentation/uikit/ui...
If you do it through XIB/Storyboard, then as far as I remember, there you can assign your controller as a delegate through the UI by dragging the delegate property in the text view onto the controller.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question