xcode – Swift UIAlertController获取文本字段文本
发布时间:2020-12-14 18:11:33 所属栏目:百科 来源:网络整理
导读:当按下“输入”按钮时,我需要从警报视图中的文本字段中获取文本. func inputMsg() { var points = "" var outOf = "" var alertController = UIAlertController(title: "Input View",message: "Please Input Your Grade",preferredStyle: UIAlertControllerS
当按下“输入”按钮时,我需要从警报视图中的文本字段中获取文本.
func inputMsg() { var points = "" var outOf = "" var alertController = UIAlertController(title: "Input View",message: "Please Input Your Grade",preferredStyle: UIAlertControllerStyle.Alert) let actionCancle = UIAlertAction(title: "Cancle",style: UIAlertActionStyle.Cancel) { ACTION in println("Cacle") } let actionInput = UIAlertAction(title: "Input",style: UIAlertActionStyle.Default) { ACTION in println("Input") println(points) println(outOf) } alertController.addAction(actionCancle) alertController.addAction(actionInput) alertController.addTextFieldWithConfigurationHandler({(txtField: UITextField!) in txtField.placeholder = "I got" txtField.keyboardType = UIKeyboardType.NumberPad points = txtField.text }) alertController.addTextFieldWithConfigurationHandler({(txtField: UITextField!) in txtField.placeholder = "Out Of" txtField.keyboardType = UIKeyboardType.NumberPad outOf = txtField.text }) presentViewController(alertController,animated: true,completion: nil) } 解决方法
UIAlertController有一个textFields属性.这是它的文本字段.您的任何处理程序都可以检查它,从而可以从任何文本字段中获取文本.
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |