我尝试了一些代码,但仍然很糟糕,所以我感谢对 Swift 菜鸟的任何帮助。
我想在每次按下回车键时隐藏多个文本字段上的键盘。
到目前为止,我的代码没有实现太多目标,因此我们将不胜感激。
谢谢!
class ViewController: UIViewController, UITextFieldDelegate {
@IBOutlet weak var priceTextField: UITextField!
@IBOutlet weak var payoutTextField: UITextField!
@IBOutlet weak var leasingPeriodTextField: UITextField!
@IBOutlet weak var priceLabel: UILabel!
@IBOutlet weak var payoutLabel: UILabel!
var amt: Int = 0
override func viewDidLoad() {
super.viewDidLoad()
priceTextField.delegate = self
priceTextField.delegate = self
priceTextField.placeholder = updateAmount()
}
func priceTextFieldShouldReturn(_ priceTextField: UITextField) -> Bool {
self.view.endEditing(true)
return true
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
最佳答案
UITextFieldDelegate
的正确方法
func textFieldShouldReturn(_ textField: UITextField) -> Bool {
textField.resignFirstResponder()
return true
}
将其替换为您命名的 priceTextFieldShouldReturn
关于ios - 在多个文本字段上隐藏键盘,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50705178/