![](/img/trans.png)
[英]How do you make a vertical text UILabel and UITextView for iOS in Swift?
[英]How do you use an alert to prompt for text in iOS with Swift?
func addPitcher(sender: UIBarButtonItem) {
var alert = UIAlertController(title: "New Pitcher", message: "Enter Name", preferredStyle: UIAlertControllerStyle.Alert)
alert.addAction(UIAlertAction(title: "Finish", style: UIAlertActionStyle.Default, handler: nil))
alert.addTextFieldWithConfigurationHandler({(textField: UITextField!) in
textField.placeholder = "Name"
textField.secureTextEntry = false
})
self.presentViewController(alert, animated: true, completion: nil)
let newName : String = alert.textFields[0] as String
println(newName)
}
这是我们尝试创建警报以提示姓名的功能。 我们在alert.addTextFieldWithConfigurationHandler({(textField: UITextField!) in
收到“EXC_BAD_INSTRUCTION”错误。
我们如何修复此错误,或者更重要的是,我们如何从字段中检索文本? 谢谢你的帮助。
您将文本字段作为字符串。 Blammo。
另外,获取处理程序中的值。
alert.addAction(UIAlertAction(title: "Ok", style: .Default, handler:{ (alertAction:UIAlertAction!) in
let textf = alert.textFields[0] as UITextField
println(textf.text)
}))
ps有时显示的错误发生在与错误消息中给出的位置不同的位置。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.