UITextFieldDelegate does not hide the keyboard

2

Good evening, comrades

I'm having a little problem with UITextFieldDelegate. I intend that when the user clicks the return key (Back) the keyboard disappears for a few moments and return the textField to write something again. But the Return and Ignore key in the act of execution and the keyboard does not disappear. of a look at the terminal

import UIKit

class ViewController: UIViewController, UITableViewDataSource, UITableViewDelegate, UITextFieldDelegate {

    @IBOutlet weak var itextField: UITextField!

    func textFieldShouldReturn(_ textField: UITextField) -> Bool {       
        itextField.resignFirstResponder()
        return true
    }
}

    
asked by anonymous 27.03.2017 / 01:40

5 answers

0

Good evening,

I solved the problem of hiding the keyboard only by delegating the textField in the View controller. Click on TextField Press control + click drag the web to the view controller shortcut at the top of the view controller scene. choose the delegate option.

    
30.03.2017 / 00:03
1

Hello

Try:

itextField.endEditing(true) 
    
29.03.2017 / 14:27
0

In your Main.storyboard, click on the TextField, go to the Attributes Inspector and look for the Keyboard option.

There you have the option to make it disappear:

Try the Dismiss interactively option.

Hugs

    
27.03.2017 / 03:33
0

To use delegate functions you need to assign the delegate of the item.

Just do itextField.delegate = self

    
13.04.2017 / 21:25
0

Unfortunately I do not know how to make the keyboard disappear for a while, but using code below, I think the keyboard will go down very fast and soon come back.

  func dismissKeyboard(){

    view.endEditing(true)
                   }

 func textFieldShouldReturn(_ textField: UITextField) -> Bool {

    if (textField == self.itextfield) {

        dismissKeyboard()
        itextfield.becomeFirstResponder()

    }else{

    return true

}
}
    
04.07.2017 / 15:37