Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

View <(null):0x0> does not conform to UITextInput protocol when tapping Return button on keyboard

This error pops up in the console when tapping return on keyboard(Real device). Everything executes as it should. Keyboard hides but this error keeps on showing in the console.

import UIKit

class ViewController: UIViewController, UITextFieldDelegate {

       lazy var nameTextField: UITextField = {
         let textField = UITextField()
         textField.placeholder = "Name:"
         textField.delegate = self
         return textField
        }()
             
        lazy var surnameTextField: UITextField = {
          let textField = UITextField()
          textField.placeholder = "Surname:"
          textField.delegate = self
          return textField
         }()
       
         override func viewDidLoad() {
              super.viewDidLoad()
               
              view.addSubview(nameTextField)
              view.addSubview(surnameTextField)

         }

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


 }
like image 515
Stefan Ovomate Avatar asked Dec 08 '20 07:12

Stefan Ovomate


1 Answers

You need to resign should you return true.

    public func textFieldShouldReturn(_ textField: UITextField) -> Bool {
        textField.resignFirstResponder()
        return true
    }
like image 84
mahan Avatar answered Sep 24 '22 22:09

mahan