下面给出的是我的alertcontroller的代码,当我在文本字段中键入内容时,我想让数字键盘出现而不是普通键盘出现。
func addPasscodeAlert()
{
let blurEffect = UIBlurEffect(style: .Light)
let blurVisualEffectView = UIVisualEffectView(effect: blurEffect)
blurVisualEffectView.frame = view.bounds
self.view.addSubview(blurVisualEffectView)
let alertController = UIAlertController(title: "No passcode saved", message: "Please enter new 4 digit passcode.", preferredStyle: .Alert)
let defaultAction = UIAlertAction(title: "OK", style: .Cancel) { (action) -> Void in
if let textField = alertController.textFields?.first as UITextField?
{
textField.keyboardType = UIKeyboardType.NumberPad
self.passcode = textField.text!
let userDefaults = NSUserDefaults.standardUserDefaults()
userDefaults.setObject(self.passcode, forKey: "passcode")
self.showPasswordAlert()
}
}
alertController.addAction(defaultAction)
alertController.addTextFieldWithConfigurationHandler { (textField) -> Void in
textField.placeholder = "Password"
textField.secureTextEntry = true
}
self.presentViewController(alertController, animated: true, completion: nil)
blurVisualEffectView.removeFromSuperview()
}
更改处理程序方法中没有的键盘类型UIAlertAction
。将您的代码替换为下面的代码。
alertController.addTextFieldWithConfigurationHandler { (textField) -> Void in
textField.keyboardType = UIKeyboardType.NumberPad
textField.placeholder = "Password"
textField.secureTextEntry = true
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句