我有一个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的东西。
我知道意见已发布回答问题,但答案应该使解决方案显式。
原文链接:https://www.f2er.com/swift/321294.html@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)