ios – 如何在警报控制器的文本框中设置数字键盘[swift]

我试图呼叫一个具有文本字段的警报控制器.但是我想立即显示数字键盘,因为用户只能输入数字.
我尝试了以下,但它不工作.
let alert = UIAlertController(title: "New rating",message: "Rate this!",preferredStyle: UIAlertControllerStyle.Alert)

  let cancelAction = UIAlertAction(title: "Cancel",style: .Default,handler: { (action: UIAlertAction!) in })

  let saveAction = UIAlertAction(title: "Save",handler: { (action: UIAlertAction!) in

    let textField = alert.textFields![0] as UITextField
    textField.keyboardType = UIKeyboardType.NumberPad

    self.updaterating(textField.text)
  })

  alert.addTextFieldWithConfigurationHandler { (textField: UITextField!) in }

  alert.addAction(cancelAction)
  alert.addAction(saveAction)

  self.presentViewController(alert,animated: true,completion: nil)

解决方法

发现自己!这可能对别人有用.
alert.addTextField(configurationHandler: { textField in
    textField.keyboardType = .numberPad
})

相关文章

UITabBarController 是 iOS 中用于管理和显示选项卡界面的一...
UITableView的重用机制避免了频繁创建和销毁单元格的开销,使...
Objective-C中,类的实例变量(instance variables)和属性(...
从内存管理的角度来看,block可以作为方法的传入参数是因为b...
WKWebView 是 iOS 开发中用于显示网页内容的组件,它是在 iO...
OC中常用的多线程编程技术: 1. NSThread NSThread是Objecti...