@IBAction func addButtonPressed(_ sender: UIBarButtonItem) {
var textField = UITextField()
let alert = UIAlertController(title: "Add New File", message:"", preferredStyle: .alert)
let action = UIAlertAction(title: "Add Item", style: .default) { (action) in
//what will happen after user clicks button
print(textField.text)
}
}
alert.addTextField { (alertTextField) in //where the error begins help
alertTextField.placeholder = "Create New File"
textField = alertTextField
}
present(alert,animated: true,completion:nil)
}
看起来你在括号中混淆了。你关闭了你的安装IBAction func
后action
。
更新代码:
@IBAction func addButtonPressed(_ sender: UIBarButtonItem) {
var textField = UITextField()
let alert = UIAlertController(title: "Add New File", message:"", preferredStyle: .alert)
let action = UIAlertAction(title: "Add Item", style: .default) { (action) in
//what will happen after user clicks button
print(textField.text)
}
alert.addTextField { (alertTextField) in //where the error begins help
alertTextField.placeholder = "Create New File"
textField = alertTextField
}
present(alert,animated: true,completion:nil)
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句