Last active
October 9, 2020 23:49
-
-
Save SlappyAUS/aafc62615537b677a1795855c2338f14 to your computer and use it in GitHub Desktop.
Alert with TextField #ui
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@IBAction func addButtonPressed(_ sender: UIBarButtonItem) { | |
let alert = UIAlertController(title: "Add New Todoey Item", message: "", preferredStyle: .alert) | |
var textField: UITextField? = nil | |
let action = UIAlertAction(title: "Add Item", style: .default) { (action) in | |
if let safeTextField = textField { | |
print(safeTextField.text ?? "") | |
} | |
} | |
alert.addTextField { (alertTextField) in | |
alertTextField.placeholder = "Create new item" | |
textField = alertTextField | |
} | |
alert.addAction(action) | |
present(alert, animated: true, completion: nil) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment