微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐