加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

swift – 从UIAlertController访问输入

发布时间:2020-12-14 06:09:06 所属栏目:百科 来源:网络整理
导读:我有一个UIAlertController,当他们选择“输入密码”在TouchID屏幕上时提示用户。如何在屏幕上显示后恢复用户的输入? let passwordPrompt = UIAlertController(title: "Enter Password",message: "You have selected to enter your passwod.",preferredStyl
我有一个UIAlertController,当他们选择“输入密码”在TouchID屏幕上时提示用户。如何在屏幕上显示后恢复用户的输入?
let passwordPrompt = UIAlertController(title: "Enter Password",message: "You have selected to enter your passwod.",preferredStyle: UIAlertControllerStyle.Alert)
passwordPrompt.addAction(UIAlertAction(title: "Cancel",style: UIAlertActionStyle.Default,handler: nil))
passwordPrompt.addAction(UIAlertAction(title: "OK",handler: nil))

passwordPrompt.addTextFieldWithConfigurationHandler({(textField: UITextField!) in
                        textField.placeholder = "Password"
                        textField.secureTextEntry = true
                        })

presentViewController(passwordPrompt,animated: true,completion: nil)

我知道OK按钮应该可能有一个处理程序,但现在这个代码没有真正做任何,但我想通过println显示文本字段的输出。这真的只是一个测试应用程序,我学习Swift和一些新的API的东西。

我知道意见已发布回答问题,但答案应该使解决方案显式。
@IBOutlet var newWordField: UITextField
    func wordEntered(alert: UIAlertAction!){
        // store the new word
        self.textView2.text = deletedString + " " + self.newWordField.text
    }
    func addTextField(textField: UITextField!){
        // add the text field and make the result global
        textField.placeholder = "Definition"
        self.newWordField = textField
    }

    // display an alert
    let newWordPrompt = UIAlertController(title: "Enter definition",message: "Trainging the machine!",preferredStyle: UIAlertControllerStyle.Alert)
    newWordPrompt.addTextFieldWithConfigurationHandler(addTextField)
    newWordPrompt.addAction(UIAlertAction(title: "Cancel",handler: nil))
    newWordPrompt.addAction(UIAlertAction(title: "OK",handler: wordEntered))
    presentViewController(newWordPrompt,completion: nil)

这将显示带有文本字段和两个操作按钮的提示。它完成后读取文本字段。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读