0

I have an edit button and when I touch that button it shows an alert view. The alert view has a text field. I customized that keyboard to "numpad". But it never change to numpad only show default keyboard. How can I do it? The code is below. Also I have tried textfield.keyboardType = .numpad in view didload and 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
    }
}
Veysel Bozkurt
  • 53
  • 2
  • 11

1 Answers1

0

Add keyboard type here.

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

Raja Kishan
  • 16,767
  • 2
  • 26
  • 52