trycatch
trycatch

Reputation: 145

text changed event in UITextView

I have

@IBOutlet weak var messageTextView: UITextView

and I want that when there is a change inside the text then print to console: blabla.

I tried to add the following function, but when I change the text nothing happens:

func textViewDidChange(_ textView: UITextView) {
    switch (textView) {
        case messageTextView: print("blabla")
        default: break
    }
}

Upvotes: 8

Views: 8347

Answers (1)

Shehata Gamal
Shehata Gamal

Reputation: 100503

You need to set the delegate inside viewDidLoad

textView.delegate = self

//

class ViewController: UIViewController , UITextViewDelegate  {

Upvotes: 11

Related Questions