[英]View <(null):0x0> does not conform to UITextInput protocol when tapping Return button on keyboard
在键盘(真实设备)上点击返回时,控制台中会弹出此错误。 一切都按原样执行。 键盘隐藏,但此错误继续显示在控制台中。
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
}
}
如果您返回true ,您需要辞职。
public func textFieldShouldReturn(_ textField: UITextField) -> Bool {
textField.resignFirstResponder()
return true
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.