![](/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.