-1

I am working with a UITextView and I need to dismiss the keyboard by pressing return key. This is what I'm doing:

class MyController: UIViewController, UITextFieldDelegate {

    @IBOutlet weak var writeNote: UITextView!

    override func viewDidLoad() {
        super.viewDidLoad()
        self.writeNote.delegate = self
}

how to proceed? When using a UITextField I would simply call the delegate for textFieldShouldReturn method but I don't appear to find anything like that for a textView. I can not use a textField because I need a larger amount of rows. The TextView tooltip says "When a user taps a text view, a keyboard appears; when a user taps Return in the keyboard, the keyboard disappears and..." but it doesn't do it by default..

1 Answers1

0

UITextView doesn't have any such direct delegate method to hide the keyboard. You have to work around with the shouldChangeTextInRange: replacementTextmethod. In this method, you can check for a new line character and if you get one, you can resign.

Natasha
  • 6,651
  • 3
  • 36
  • 58