简体   繁体   中英

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
    }


 }

You need to resign should you return true .

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM