Ios 在多个文本字段上隐藏键盘
我尝试了一些代码,但我仍然很差劲,所以我感谢任何对快速noob的帮助 我想在每次按下enter键时隐藏多个文本字段上的键盘 到目前为止,我的代码还没有实现任何功能,因此非常感谢您的帮助 谢谢Ios 在多个文本字段上隐藏键盘,ios,swift,uitextfield,iboutlet,Ios,Swift,Uitextfield,Iboutlet,我尝试了一些代码,但我仍然很差劲,所以我感谢任何对快速noob的帮助 我想在每次按下enter键时隐藏多个文本字段上的键盘 到目前为止,我的代码还没有实现任何功能,因此非常感谢您的帮助 谢谢 class ViewController: UIViewController, UITextFieldDelegate { @IBOutlet weak var priceTextField: UITextField! @IBOutlet weak var payoutTextField: UITextF
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
}
func textFieldShouldReturn(_ textField: UITextField) -> Bool {
textField.resignFirstResponder()
return true
}
将其替换为您命名的pricetextfield应返回您需要为每个textfield设置代理
priceTextField.delegate = self
payoutTextField.delegate = self
leasingPeriodTextField. delegate = self
并从UITextFieldDelegateProtocol