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

标签 ios swift uitextfield iboutlet

我尝试了一些代码,但仍然很糟糕,所以我感谢对 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/

相关文章:

arrays - 在结构数组中设置特定的变量

ios - 更改 UITextField 占位符字体

ios - 根据计算值 [Swift] 使用 slider 更改文本字段中的值

ios - MKMapView 显示用户位置崩溃

ios - 如何在 iOS 上获取有关传感器的信息?

ios - SpriteKit 节点未从父节点中删除

ios - 如何在行的 TableView 单元格内的另一个数组内迭代数组

IOS - 标签栏项目图像修改

ios - Swift:线程 1 信号 SIGABRT

ios - 添加到 UITextField 的 CALayer 不会出现在 xib View 上