Created
January 20, 2020 19:01
-
-
Save crgg/87420996b73f61c8cb7912d2afdbc355 to your computer and use it in GitHub Desktop.
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
// Implement the addName IBAction | |
@IBAction func addName(_ sender: UIBarButtonItem) { | |
let alert = UIAlertController(title: "New Name", | |
message: "Add a new name", | |
preferredStyle: .alert) | |
let saveAction = UIAlertAction(title: "Save", | |
style: .default) { | |
[unowned self] action in | |
guard let textField = alert.textFields?.first, | |
let nameToSave = textField.text else { | |
return | |
} | |
self.names.append(nameToSave) | |
self.tableView.reloadData() | |
} | |
let cancelAction = UIAlertAction(title: "Cancel", | |
style: .cancel) | |
alert.addTextField() | |
alert.addAction(saveAction) | |
alert.addAction(cancelAction) | |
present(alert, animated: true) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment