Skip to content

Instantly share code, notes, and snippets.

@BalajiMalliswamy
Last active May 30, 2018 07:26
Show Gist options
  • Save BalajiMalliswamy/75158d6292788bec2690d03310711957 to your computer and use it in GitHub Desktop.
Save BalajiMalliswamy/75158d6292788bec2690d03310711957 to your computer and use it in GitHub Desktop.
Exploring UIAlertController in swift
/**
Simple Alert with Text input
*/
func showAlertWithTextField() {
let alertController = UIAlertController(title: "Add new tag", message: nil, preferredStyle: .alert)
let confirmAction = UIAlertAction(title: "Add", style: .default) { (_) in
if let txtField = alertController.textFields?.first, let text = txtField.text {
// operations
print("Text==>" + text)
}
}
let cancelAction = UIAlertAction(title: "Cancel", style: .cancel) { (_) in }
alertController.addTextField { (textField) in
textField.placeholder = "Tag"
}
alertController.addAction(confirmAction)
alertController.addAction(cancelAction)
self.present(alertController, animated: true, completion: nil)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment