Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/112.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 在多个文本字段上隐藏键盘_Ios_Swift_Uitextfield_Iboutlet - Fatal编程技术网

Ios 在多个文本字段上隐藏键盘

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

我尝试了一些代码,但我仍然很差劲,所以我感谢任何对快速noob的帮助

我想在每次按下enter键时隐藏多个文本字段上的键盘

到目前为止,我的代码还没有实现任何功能,因此非常感谢您的帮助

谢谢

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