Uitextfielddelegate does not hide the keyboard

Asked

Viewed 241 times

2

Good night, fellas

I’m having a little trouble with Uitextfielddelegate. I intend that when the user clicks the return key (Back) the keyboard disappears for a few moments and goes back to textField to write something again. But the Return key is ignored in the execution act and the keyboard does not disappear. from 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
    }
}

print de tela

5 answers

1

Hello

Try:

itextField.endEditing(true) 
  • Good, I tested with this function also worked, however the problem was not in the code. Thanks @Felipe Ricieri

0

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

There you have the option to make it disappear:

inserir a descrição da imagem aqui

Try the option Dismiss.

Hugs

  • In my does not appear, maybe it is the version of our Xcode mine is Version 8.2.1 (8C1002)

  • Sorry, this option is for Text View. I tried some options for Text Field, but I couldn’t find anything useful!! Sorry

  • 1

    It’s okay. Brother we’re together

0

Unfortunately I do not know how to make the keyboard disappear for a few moments, but using code below, I think the keyboard will descend very fast and soon return.

  func dismissKeyboard(){

    view.endEditing(true)
                   }

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

    if (textField == self.itextfield) {

        dismissKeyboard()
        itextfield.becomeFirstResponder()

    }else{

    return true

}
}
  • There Renato already managed to solve below are the prints and the solution.

0


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

print

0

To use delegate functions you need to assign item delegate.

Just make itextField.delegate = self

Browser other questions tagged

You are not signed in. Login or sign up in order to post.