大佬教程收集整理的这篇文章主要介绍了从Swift中的iOS警报中的TextField获取输入值,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
//1. Create the alert controller. let alert = UIAlertController(title: "Some title",message: "Enter a text",preferredStyle: .alert) //2. Add the text field. You can configure it however you need. alert.addTextField { (textField) in textField.text = "Some default text" } // 3. Grab the value from the text field,and print it when the user clicks OK. alert.addAction(UIAlertAction(title: "OK",style: .default,handler: { [weak alert] (_) in let textField = alert.textFields![0] // Force unwrapping because we kNow it exists. print("Text field: \(textField.text)") })) // 4. Present the alert. self.present(alert,animated: true,completion: nil)
Swift 2.x
假设您想要在iOS上显示动作快讯:
//1. Create the alert controller. var alert = UIAlertController(title: "Some title",preferredStyle: .Alert) //2. Add the text field. You can configure it however you need. alert.addTextFieldWithConfigurationHandler({ (textField) -> Void in textField.text = "Some default text." }) //3. Grab the value from the text field,and print it when the user clicks OK. alert.addAction(UIAlertAction(title: "OK",style: .Default,handler: { [weak alert] (action) -> Void in let textField = alert.textFields![0] as UITextField println("Text field: \(textField.text)") })) // 4. Present the alert. self.presentViewController(alert,completion: nil)
以上是大佬教程为你收集整理的从Swift中的iOS警报中的TextField获取输入值全部内容,希望文章能够帮你解决从Swift中的iOS警报中的TextField获取输入值所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。