我有一个编辑按钮,当我触摸该按钮时,它会显示一个警报视图。警报视图有一个文本字段。我将该键盘自定义为“数字键盘”。但它永远不会更改为仅显示默认键盘的小键盘。我该怎么做?代码如下。我也尝试textfield.keyboardType = .numpad
过查看didload和editbuttonclicked func
@IBAction func editQuantityButtonClicked(_ sender: Any) {
var textField = UITextField()
let alert = UIAlertController(title: "", message: "Enter a quantity", preferredStyle: .alert)
let action = UIAlertAction(title: "Ok", style: .default) { (anAction) in
if let aText = textField.text{
self.pickerDataLabel.text = "\(aText) mL"
}
}
alert.addAction(action)
self.present(alert, animated: true, completion: nil)
alert.addTextField { (aText) in
textField = aText
}
}
在此处添加键盘类型。
alert.addTextField { (aText) in
aText.keyboardType = .numberPad //<-- Here
textField = aText
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句