【问题标题】:unopened numeric and other keyboard on textfield alertView in swiftswift中文本字段alertView上未打开的数字和其他键盘
【发布时间】:2021-06-02 02:36:57
【问题描述】:

我有一个编辑按钮,当我触摸该按钮时,它会显示一个警报视图。警报视图有一个文本字段。我将该键盘定制为“小键盘”。但它永远不会更改为 numpad 只显示默认键盘。我该怎么做? 代码如下。我也试过textfield.keyboardType = .numpad 在视图中 didload 和 editbuttonclicked 函数

@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
    }
}

【问题讨论】:

  • 感谢它对我有用

标签: swift keyboard uitextfield uialertview numpad


【解决方案1】:

在此处添加键盘类型。

alert.addTextField { (aText) in
    aText.keyboardType = .numberPad //<-- Here
    textField = aText
}

【讨论】:

    猜你喜欢
    • 2019-09-18
    • 1970-01-01
    • 2021-06-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-04-21
    • 1970-01-01
    相关资源
    最近更新 更多