swift – 从UIAlertController访问输入

我有一个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)

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

相关文章

软件简介:蓝湖辅助工具,减少移动端开发中控件属性的复制和粘...
现实生活中,我们听到的声音都是时间连续的,我们称为这种信...
前言最近在B站上看到一个漂亮的仙女姐姐跳舞视频,循环看了亿...
【Android App】实战项目之仿抖音的短视频分享App(附源码和...
前言这一篇博客应该是我花时间最多的一次了,从2022年1月底至...
因为我既对接过session、cookie,也对接过JWT,今年因为工作...